Skip to content

Fix debug SQL tracking for composed queries - #1566

Open
2836048681 wants to merge 1 commit into
graphql-python:mainfrom
2836048681:fix/960-debug-sql-non-string
Open

2836048681 wants to merge 1 commit into
graphql-python:mainfrom
2836048681:fix/960-debug-sql-non-string

Conversation

@2836048681

Copy link
Copy Markdown
  • Repository graphql-python/graphene-django
  • Base main at 0e6ef22
  • Branch fix/960-debug-sql-non-string at fa985dd

Summary

Passing a psycopg2.sql.Composed query to cursor.execute() succeeds at the driver but raises AttributeError in DjangoDebugMiddleware when the middleware calls .lower() on the query object. Use the SQL text returned by Django’s backend to classify non-string queries. If the backend has no SQL text, record the query as having no detected SELECT.

Fixes #960

Testing

  • Both new cases reproduce the reported error on the base code. They use real psycopg2.sql.Composed objects and mock the cursor and backend, so no PostgreSQL server is needed.
  • python -m pytest --cov=graphene_django graphene_django examples -q --tb=short passed all 407 tests on Python 3.12.3 with Django 5.2.19 and psycopg2-binary 2.9.13.
  • ruff check graphene_django examples, Ruff formatting on the two changed files, and git diff --check passed.

Fixes #960.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using DjangoDebugMiddleware, debug tracking presumes cursor.execute argument is a string, raising an error

1 participant