Commit Graph

12 Commits

Author SHA1 Message Date
Mike Bayer 27c0dafbeb add session-wide execution_options
Added support for per-session execution options that are merged into all
queries executed within that session. The :class:`_orm.Session`,
:class:`_orm.sessionmaker`, :class:`_orm.scoped_session`,
:class:`_ext.asyncio.AsyncSession`, and
:class:`_ext.asyncio.async_sessionmaker` constructors now accept an
:paramref:`_orm.Session.execution_options` parameter that will be applied
to all explicit query executions (e.g. using :meth:`_orm.Session.execute`,
:meth:`_orm.Session.get`, :meth:`_orm.Session.scalars`) for that session
instance.

Fixes: #12659
Change-Id: I6e19e1567e0c04df32ba1d43baf420fb762f155c
2025-08-31 09:53:02 -04:00
Federico Caselli d539bc3a0f update the format_docs_code to also work on python files
Change-Id: I0a6c9610b3fd85365ed4c2c199e3cad87ee64022
2024-11-30 21:10:21 +01:00
Federico Caselli 73344fd0d3 Fix select.with_only_columns type hints
Fixes: #11782
Change-Id: Idce218a9730986d3ca70547c83aa1c0f8b5ee5b2
2024-08-28 21:52:30 +02:00
Carlos Sousa dc8b7cb5fd Add get_one to Session, AsyncSession, scoped, etc
Added method :meth:`_orm.Session.get_one` that behaves like
meth:`_orm.Session.get` but raises an exception instead of returning
None`` if no instance was found with the provided primary key.
Pull request courtesy of Carlos Sousa.

Fixed the :paramref:`_asyncio.AsyncSession.get.execution_options` parameter
which was not being propagated to the underlying :class:`_orm.Session` and
was instead being ignored.

Fixes #10292
Closes: #10376
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10376
Pull-request-sha: 70e4505e93

Change-Id: I78eb9816c26446757b6c6c171df2e400777a3d36
2023-10-01 09:07:44 -04:00
Federico Caselli 058c230cea Update black to v23.3.0 and flake8 to v6
This change could be added to .git-blame-ignore-revs

Change-Id: I7ba10052b26bc3c178d23fb50a1123d0aae965ca
2023-05-30 21:44:26 +02:00
Mike Bayer cd96ffe287 refactor code generation tools , include --check command
in particular it looks like CI was not picking up on the
"git diff" oriented commands, which were failing to run due
to pathing issues.  As we were setting cwd for black/zimports
relative to sqlalchemy library, and tox installs it in
the venv, black/zimports would fail to run from tox, and
since these are subprocess.run we didn't pick up the
failure.

This overall locks down how zimports/black are run
so that we are definitely from the source root, by using
the location of tools/ to determine the root.

Fixes: #8892
Change-Id: I7c54b747edd5a80e0c699b8456febf66d8b62375
2023-01-18 15:07:55 -05:00
Federico Caselli d10b62f54e Improve typings of execution options
Fixes: #8605
Change-Id: I4aec83b9f321462427c3f4ac941c3b272255c088
2022-11-02 21:38:31 -04:00
Federico Caselli 3668889426 Improve proxy methods with the changes from the abandoned
I5c7f172e5224fa08d0675160ac919d0b045a26eb

Change-Id: Ieb7971297f959fd635a4627bd93154e28ef0ef2b
2022-10-18 19:57:19 +02:00
Mike Bayer a45e5f1754 use black 22.8.0
nothing happened moving from 22.3 to 22.8.  a full run of pre-commit
found some little things in the generate_proxy_methods script.

Change-Id: Ie6b4235b87bbfcb252759c0afb133ab8d0cf51db
2022-10-03 17:40:08 -04:00
Mike Bayer ad11c482e2 pep484 ORM / SQL result support
after some experimentation it seems mypy is more amenable
to the generic types being fully integrated rather than
having separate spin-off types.   so key structures
like Result, Row, Select become generic.  For DML
Insert, Update, Delete, these are spun into type-specific
subclasses ReturningInsert, ReturningUpdate, ReturningDelete,
which is fine since the "row-ness" of these constructs
doesn't happen until returning() is called in any case.

a Tuple based model is then integrated so that these
objects can carry along information about their return
types.  Overloads at the .execute() level carry through
the Tuple from the invoked object to the result.

To suit the issue of AliasedClass generating attributes
that are dynamic, experimented with a custom subclass
AsAliased, but then just settled on having aliased()
lie to the type checker and return `Type[_O]`, essentially.
will need some type-related accessors for with_polymorphic()
also.

Additionally, identified an issue in Update when used
"mysql style" against a join(), it basically doesn't work
if asked to UPDATE two tables on the same column name.
added an error message to the specific condition where
it happens with a very non-specific error message that we
hit a thing we can't do right now, suggest multi-table
update as a possible cause.

Change-Id: I5eff7eefe1d6166ee74160b2785c5e6a81fa8b95
2022-04-27 14:46:36 -04:00
Mike Bayer aa9cd878e8 pep-484: session, instancestate, etc
Also adds some fixes to annotation-based mapping
that have come up, as well as starts to add more
pep-484 test cases

Change-Id: Ia722bbbc7967a11b23b66c8084eb61df9d233fee
2022-04-12 02:09:50 +00:00
Mike Bayer 98eae4e181 use code generation for scoped_session
our decorator thing generates code in any case,
so point it at the file itself to generate real code
for the blocks rather than doing things dynamically.

this will allow typing tools to have no problem
whatsoever and we also reduce import time overhead.
file size will be a lot bigger though, shrugs.

syntax / dupe method / etc. checking will be accomplished
by our existing linting / typing / formatting tools.

As we are also using "from __future__ import annotations",
we also no longer have to apply quotes to generated
annotations.

Change-Id: I20962cb65bda63ff0fb67357ab346e9b1ef4f108
2022-04-12 02:09:42 +00:00