-
-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve type annotation for RunSQL #1090
Conversation
The sqls to be executed do not necessarily need to be a homogeneous list or tuple containing only lists or tuples or strs. It can be a mix of everything. Signed-off-by: Zixuan James Li <[email protected]>
The 2-item tuple for `sql` can have a `dict` as the second item for parameters. This behavior is the same as using `cursor.execute` for backends except SQLite. Relevant implementation: https://github.com/django/django/blob/5f760025004bdb02f9844011033459c30347f215/django/db/migrations/operations/special.py#L119-L133 Signed-off-by: Zixuan James Li <[email protected]>
Signed-off-by: Zixuan James Li <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@@ -21,15 +21,17 @@ class SeparateDatabaseAndState(Operation): | |||
|
|||
class RunSQL(Operation): | |||
noop: Literal[""] = ... | |||
sql: Union[str, _ListOrTuple[str], _ListOrTuple[Tuple[str, Optional[_ListOrTuple[str]]]]] = ... | |||
reverse_sql: Optional[Union[str, _ListOrTuple[str], _ListOrTuple[Tuple[str, Optional[_ListOrTuple[str]]]]]] = ... | |||
sql: Union[str, _ListOrTuple[Union[str, Tuple[str, Union[Dict[str, Any], Optional[_ListOrTuple[str]]]]]]] = ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes... I know
This causes false positive when used with a sqls: list[str] = ["SOME SQLS", "SOME SQLS"]
RunSQL(sql=sqls, reverse_sql=[])
I don't think there's a simple fix though. Ordinariy we would change |
Wild guess: maybe moving |
I have made things!
The
sql
s to be executed do not necessarily need to be a homogeneous listor tuple containing only lists or tuples or
str
s. It can be a mix ofeverything acceptable for the cursor.
RunSQL
iterates through the list or tupleand executes them separately.
Also, the 2-item tuple for
sql
can have adict
as the second itemfor parameters. This behavior is the same as using
cursor.execute
for backends except for SQLite.A test case is added along with this change.
Relevant implementation
https://github.com/django/django/blob/5f760025004bdb02f9844011033459c30347f215/django/db/migrations/operations/special.py#L119-L133
Related issues