Skip to content
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

Fix psycopg3 tests #1773

Merged
merged 4 commits into from
May 12, 2023
Merged

Fix psycopg3 tests #1773

merged 4 commits into from
May 12, 2023

Commits on May 10, 2023

  1. Configuration menu
    Copy the full SHA
    df67c89 View commit details
    Browse the repository at this point in the history
  2. Don't try to undo DatabaseWrapper monkey patching

    Prior to this commit, the SQLPanel would monkey patch the .cursor() and
    .chunked_cursor() methods of each DatabaseWrapper connection in
    .enable_instrumentation(), and then undo the monkey patch in
    .disable_instrumentation().  However, for the same reasons as
    a6b65a7, stop trying to undo the monkey
    patching in .disable_instrumentation() and simply use a .djdt_logger
    attribute on the DatabaseWrapper to determine if the cursors should be
    wrapped.
    living180 committed May 10, 2023
    Configuration menu
    Copy the full SHA
    217238b View commit details
    Browse the repository at this point in the history
  3. Fix psycopg3 tests

    Several tests (such as SQLPanelTestCase.test_cursor_wrapper_singleton)
    are written to ensure that only a single cursor wrapper is instantiated
    during the test.  However, this fails when using Django's psycopg3
    backend, since the .last_executed_query() call in
    NormalCursorWrapper._record() ends up creating an additional cursor (via
    [1]).  To avoid this wrapping this additional cursor, set the
    DatabaseWrapper's ._djdt_logger attribute to None before calling
    .last_executed_query() and restore it when finished.  This will cause
    the monkey-patched DatabaseWrapper .cursor() and .chunked_cursor()
    methods to return the original cursor without wrapping during that call.
    
    [1] https://github.com/django/django/blob/4.2.1/django/db/backends/postgresql/psycopg_any.py#L21
    living180 committed May 10, 2023
    Configuration menu
    Copy the full SHA
    32ab363 View commit details
    Browse the repository at this point in the history

Commits on May 11, 2023

  1. Inherit from django.db.backends.utils.CursorWrapper

    This switches the Debug Toolbar cursor wrappers to inherit from the
    Django class django.db.backends.utils.CursorWrapper. This reduces some
    of the code we need.
    tim-schilling authored and living180 committed May 11, 2023
    Configuration menu
    Copy the full SHA
    e7575e8 View commit details
    Browse the repository at this point in the history