inspectable Query (for relationships)

Issue #3654 duplicate
jvanasco created an issue

There doesn't seem to be a (public) way to find out if a path has been registered to a query for eager loading. (A non-public way seems to be query.__dict__['with_options'])

I propose an enhancement to the Query API, which allows a query to be queried for the status of eager loads.

In the simplest concept, it would just return a dict where the keys are a stringified path, and the values are the type of load (joinedload vs subqueryload vs contains_eager). If there is no eager loading for a given relationship, then the key is absent.

print q.registered_eagers()
> {'foo': 'joinedload', 'foo.bar':' subqueryload', 'foo.biz': 'contains_eager'}

The use-case is when dealing with generative queries that are loading relationships several layers deep; it becomes increasingly hard to ensure you have a load-strategy for each intermediary relationship..

Comments (4)

  1. jvanasco reporter

    Ah, sorry. Well here's another use-case!

    FWIW, I did spent about 30 minutes searching though back tickets for possible dupes, but I didn't see the query inspection one. I was focused on the eager loading keywords.

  2. Log in to comment