-
Notifications
You must be signed in to change notification settings - Fork 766
__debug, __sql doesn't log sql queries made withing promises or resolves In Types #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
for example I only see three queries here, but In reality Im making queries to resolve products, but it doesn't show up.
and this is the query that isn't being showed, This query happens in a Type
|
it seems that because the promise resolves after the schema.execute returns there is no way for the __debug middleware from graphene to know which sql actually executed. |
I may be wrong, but it seems to me it's affecting every case where I query through reverse Foreign Key relation. For example, with the following query:
And the Schema query:
And Product Django Object Type
I'll see a query for Products reported, but none for Variants (although it is happening). |
Yes I think that the sql tag should be resolved after the rest of the query is resolved .. even after promises are resolved in the query. That would resolve a lot of issues. |
I've just hit the same issue. It was suspicious that I don't see N+1 queries when I skipped As a workaround, I'm auditing sql in tests using snapshots. I use this wrapper around snapshottest: id_re = re.compile(r'(_?id["\']) = \d+')
in_re = re.compile(r"IN \(\d+(\s?, \d+)*\)")
# project specific substitution
key_re = re.compile(r'(_?key["\']) = \'\w+\'')
@pytest.fixture
def assert_sql_snapshot(snapshot):
"""
Create/compare a snapshot of sql queries which were executed inside this context.
IDs are replaced with `ID` placehodler to assure independence on db sequences.
"""
@contextmanager
def _assert():
with CaptureQueriesContext(connection) as context:
yield
queries = ";".join(query["sql"] for query in context)
queries = id_re.sub(r"\1 = ID", queries)
queries = in_re.sub(r"IN (IDs)", queries)
queries = key_re.sub(r"\1 = KEY", queries)
sql = sqlparse.format(queries, reindent=True, keyword_case="upper")
snapshot.assert_match(sql)
return _assert Then I wrap the def test_query(self, client, assert_sql_snapshot):
with assert_sql_snapshot():
executed = client.execute(...)
# other asserts When the snapshot is generated, I check that there're no extra queries. It's also useful to check if the query could be further optimized. |
Looking at the code of that middleware, I see it waits for all promises that where seen by the middleware before starting to resolve
Edit: it works, I've made a PR out of it: #591. |
This commits makes sure DebugContext waits for fields that started to resolve after __debug has. Fixes graphql-python#293.
This commit makes DjangoDebugContext wait for all field's promises, even for fields that only started their resolvers after __debug was resolved. Fixes graphql-python#293.
Closing this down as I see we have a PR out of it (thanks @ktosiek!). |
* Make DjangoDebugContext wait for nested fields This commit makes DjangoDebugContext wait for all field's promises, even for fields that only started their resolvers after __debug was resolved. Fixes #293. * Run format
Hello world, I have a query that has promises with data loaders, In those dataloaders I do queries that don't show up in
the queries
The text was updated successfully, but these errors were encountered: