Skip to content

Fix sqlite3 cursor and placeholder syntax in get_row_from_db (#895)#907

Open
harminius wants to merge 3 commits into
masterfrom
fix/issue-895-sqlite-cursor
Open

Fix sqlite3 cursor and placeholder syntax in get_row_from_db (#895)#907
harminius wants to merge 3 commits into
masterfrom
fix/issue-895-sqlite-cursor

Conversation

@harminius
Copy link
Copy Markdown
Contributor

Summary

Fixes #895 — clicking a version in the Changes viewer raised:

TypeError: 'sqlite3.Cursor' object does not support the context manager protocol
  at Mergin/diff.py:78 in get_row_from_db

get_row_from_db in Mergin/diff.py was written with psycopg2 conventions even though db_conn is a stdlib sqlite3.Connection:

  • with db_conn.cursor() as c:sqlite3.Cursor is not a context manager (only sqlite3.Connection is).
  • '"{}" = %s' placeholders — sqlite3 uses ?, not %s.

Changes

  • Drop the with wrapper; assign cursor directly
  • %s? for parameter placeholders.

@harminius harminius requested a review from varmar05 May 11, 2026 09:07
@varmar05
Copy link
Copy Markdown
Contributor

@harminius does this mean this was never working?

also I do not see using context manager with connection object - would be good to review gpkg handling here and wrap it up

@harminius
Copy link
Copy Markdown
Contributor Author

harminius commented May 14, 2026

@varmar05
The bug(s) have been there for two months, as it was introduced with SQL sanitization cd2c4a7

As of context manages

@harminius
Copy link
Copy Markdown
Contributor Author

harminius commented May 15, 2026

unlike the connection, cursor doesn't lock any OS-level resources
sqlite3 can create the cursor implicitly with the .execute() method

I would prefer not to worry about its lifecycle and use the shortcut

https://docs.python.org/3/library/sqlite3.html#sqlite3-connection-shortcuts

@harminius
Copy link
Copy Markdown
Contributor Author

Closing the SQL connection might fix this dinosaur: #473

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.

TypeError when clicking on a version in Changes viewer (history)

2 participants