Skip to content

Instantly share code, notes, and snippets.

@rixx
Last active May 16, 2025 10:24
Show Gist options
  • Save rixx/e64a074445ec8adb7ddf18d35c06e6a5 to your computer and use it in GitHub Desktop.
Save rixx/e64a074445ec8adb7ddf18d35c06e6a5 to your computer and use it in GitHub Desktop.

Revisions

  1. rixx revised this gist May 16, 2025. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions debug.py
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,9 @@
    # @breakpoint_on_query()
    # Or use as `with breakpoint_on_query():`


    from contextlib import contextmanager
    @contextmanager
    def breakpoint_on_query():
    from contextlib import contextmanager
    from django.db import connection
    def instrument(execute, sql, params, many, context):
    # Optional: match only specific queries, e.g.
  2. rixx created this gist May 14, 2025.
    17 changes: 17 additions & 0 deletions debug.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # Use: wrap methods:
    # @breakpoint_on_query()
    # Or use as `with breakpoint_on_query():`


    @contextmanager
    def breakpoint_on_query():
    from contextlib import contextmanager
    from django.db import connection
    def instrument(execute, sql, params, many, context):
    # Optional: match only specific queries, e.g.
    # if sql.startswith("DELETE"), or "foo_table" in sql
    breakpoint()
    return execute(sql, params, many, context)

    with connection.execute_wrapper(instrument):
    yield