Skip to content

fix(django-cf): return a fresh new cursor for every cursor call - #205

Open
ryanking13 wants to merge 1 commit into
mainfrom
gyeongjae/cursor-dup
Open

fix(django-cf): return a fresh new cursor for every cursor call#205
ryanking13 wants to merge 1 commit into
mainfrom
gyeongjae/cursor-dup

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

Fixes a bug that calling cursor() against a database connection was returning always the same cursor.

cursorA = connection.cursor()
cursorB = connection.cursor()

assert cursorA != cursorB  # should not be the same!

@ask-bonk

ask-bonk Bot commented Aug 14, 2026

Copy link
Copy Markdown

The change looks clean and correct. The PR:

  1. Extracts cursor behavior into a separate CFCursor class so CFDatabase.cursor() returns a fresh instance each call, fixing the shared-cursor bug.
  2. CFCursor correctly proxies _defer_foreign_keys to the shared CFDatabase state.
  3. Tests are thorough — they cover cursor independence, shared defer_foreign_keys state, and a real-world nested queryset scenario.
  4. The test_iterator_chunk_size_one_survives_nested_foreign_key_queries test is an excellent integration test that validates the exact bug scenario.

LGTM

github run

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.

1 participant