-
-
Notifications
You must be signed in to change notification settings - Fork 666
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
Add an overload to the exec
method with _Executable
statement for update and delete statements
#909
Comments
This is also valid for insert statements |
I agree. The Yes,
When using direct SQL statements, especially when preparing user input, it needs to be wrapped with the To safely perform SQL queries, you need to wrap them in
However, the problem arises because In other words, at least in the If only select statements are allowed, execute and exec should be considered as functions with different characteristics. Steps to Reproduce:
Expected Behavior: Actual Behavior: I've been checking and testing this and it does indeed output an error.
Additional Notes: |
I run into this issue to. Do we have any update? |
@sandangel |
But
|
One workaround is to use This could also cause the local ORM state to be stale so just be wary to refresh relevant ORM objects if you need to use them. Also, if you need to pass in custom options there are some discrepancies between the |
I just use the sqlalchemy AsyncSession and use |
These workarounds falling back to raw SQLAlchemy instead of SQLModel feel clunky and confusing to me. def delete_bulk_objects(model: type[T], conditions: list[Any], session: Session):
statement = delete(model).where(*conditions)
session.exec(statement) # without type: ignore, it shows the 'session.exec(statement)' error.
session.commit() |
I'm kind of confused as to why there's so much discussion about working around this using unwrapped sqlalchemy. Calling Am I missing something? If not, why isn't it just added as another overload? |
Can confirm that exec works, but raises mypy errors:
|
I think we should add an overload to the
exec
method to still have the possibility of passing an_Executable
statement:Originally posted by @joachimhuet in #831 (comment)
The text was updated successfully, but these errors were encountered: