Fix bug in set_generated_identity#38
Merged
Merged
Conversation
set_generated_identity
Coverage Report Results
1 empty file skipped. |
30addbe to
71517cf
Compare
felcury
reviewed
Jun 5, 2025
Comment on lines
446
to
+447
| self.cur.execute( | ||
| sql=psycopg.sql.SQL( | ||
| psycopg.sql.SQL( |
There was a problem hiding this comment.
Could you also change the signature of LoggedCursor's execute to take sql as a positional-only argument? That way, it's impossible to use it incorrectly
class LoggedCursor:
# ...
def execute(self, sql: str, /) -> None: ...
Contributor
Author
There was a problem hiding this comment.
Yes, that's probably a better fix.
LoggedCursor.execute has a parameter "sql", but the native Psycopg "cursor" type's execute method has the parameter named "query" instead. This test shows that calling execute with a named argument "sql" throws an exception when used with a native cursor.
This change prevents the kind of issue fixed in the previous commit from ever happening again by making cur.execute(sql="") calls throw a TypeError.
71517cf to
7ac2c24
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using Psycopack with Django, we give it a native psycopg2 cursor. That cursor class's
executemethod names its first parameter asquery. But in one place, Psycopack calls thecursor.executewith a named argumentsql. That works with theLoggedCursortype used in Psycopack's tests, but throws an exception with psycopg2's nativecursortype.This PR adds a test to illustrate the problem, and changes the problematic method call to use a positional argument. It also changes
LoggedCursor.executeto only accept positional arguments, so that it's not possible for this issue to happen again.The PR also updates the
.gitignorefile to include files belonging to common IDEs.