Skip to content

✨ Add overload for exec method to support insert, update, delete statements #1342

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

seriaati
Copy link

To address #909

@seriaati seriaati changed the title Add _Executable overload for exec method in AsyncSession and Session ✨ Add _Executable overload for exec method in AsyncSession and Session Apr 10, 2025
@seriaati seriaati marked this pull request as draft April 10, 2025 01:21
@seriaati seriaati changed the title ✨ Add _Executable overload for exec method in AsyncSession and Session ✨ Add UpdateBase overload for exec method in AsyncSession and Session Apr 10, 2025
@seriaati seriaati marked this pull request as ready for review April 10, 2025 01:31
@svlandeg svlandeg added the feature New feature or request label Apr 10, 2025
@superboum
Copy link

superboum commented Jun 3, 2025

On #1349 you asked for feedbacks on your PR: I tested it and it fixed my typing errors!

Previously I had this mypy output:

src/ddd/infrastructure/manager.py:263: error: No overload variant of "exec" of "Session" matches argument type "Update"  [call-overload]
src/ddd/infrastructure/manager.py:263: note: Possible overload variants:
src/ddd/infrastructure/manager.py:263: note:     def [_TSelectParam: Any] exec(self, statement: Select[_TSelectParam], *, params: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = ..., execution_options: Mapping[str, Any] = ..., bind_arguments: dict[str, Any] | None = ..., _parent_execute_state: Any | None = ..., _add_event: Any | None = ...) -> TupleResult[_TSelectParam]
src/ddd/infrastructure/manager.py:263: note:     def [_TSelectParam: Any] exec(self, statement: SelectOfScalar[_TSelectParam], *, params: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = ..., execution_options: Mapping[str, Any] = ..., bind_arguments: dict[str, Any] | None = ..., _parent_execute_state: Any | None = ..., _add_event: Any | None = ...) -> ScalarResult[_TSelectParam]

After applying your patch, the type error is solved.
Thanks a lot, hope your patch will be merged soon so everyone can benefit from this typing fix in sqlmodel 🌟

@pizzashuai
Copy link

Hope this gets merged soon! Good job @seriaati

@YuriiMotov YuriiMotov changed the title ✨ Add UpdateBase overload for exec method in AsyncSession and Session ✨ Add overload for exec method to support insert, update, delete statements Aug 15, 2025
Copy link

@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

This fixes the typing issue when we use exec method with insert, update or delete statements. Currently it works, but type checkers raise warnings. This PR fixes this.

@seriaati, thanks for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an overload to the exec method with _Executable statement for update and delete statements
5 participants