Skip to content

Conversation

@jy-tan
Copy link
Contributor

@jy-tan jy-tan commented Jan 29, 2026

Summary

Fixes a bug where Django apps with django.contrib.postgres in INSTALLED_APPS would crash during startup in REPLAY mode with TypeError: 'MockCursor' object is not iterable.

Django's postgres extension iterates over cursor results to register type handlers (hstore, citext, etc.):

# django/contrib/postgres/signals.py
for row in cursor:
    ...

The MockCursor class was missing __iter__ and __next__ methods required for this iteration pattern.

Changes

  • Add __iter__ and __next__ methods to MockCursor class for REPLAY mode cursor iteration
  • Add __iter__ and __next__ methods to InstrumentedCursor class for RECORD mode cursor iteration (uses stored _tusk_rows after _finalize_query_span captures rows)
  • Add django.contrib.postgres to the django-postgres stack test to validate the fix
  • Add /db/cursor-iteration test endpoint that exercises for row in cursor syntax

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

@jy-tan jy-tan merged commit 6d8dce2 into main Jan 29, 2026
22 checks passed
@jy-tan jy-tan deleted the django-pg-cursor-iteration branch January 29, 2026 08:19
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.

3 participants