2.0.22
Released: October 12, 2023
orm
-
[orm] [usecase] Added method
_orm.Session.get_one()
that behaves like
_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.References: #10202
-
[orm] [usecase] Added an option to permanently close sessions.
Set toFalse
the new parameter_orm.Session.close_resets_only
will prevent a_orm.Session
from performing any other
operation after_orm.Session.close()
has been called.Added new method
_orm.Session.reset()
that will reset a_orm.Session
to its initial state. This is an alias of_orm.Session.close()
,
unless_orm.Session.close_resets_only
is set toFalse
.References: #7787
-
[orm] [bug] Fixed a wide range of
_orm.mapped_column()
parameters that were not
being transferred when using the_orm.mapped_column()
object inside
of a pep-593Annotated
object, including
_orm.mapped_column.sort_order
,
_orm.mapped_column.deferred
,
_orm.mapped_column.autoincrement
,
_orm.mapped_column.system
,_orm.mapped_column.info
etc.Additionally, it remains not supported to have dataclass arguments, such as
_orm.mapped_column.kw_only
,
_orm.mapped_column.default_factory
etc. indicated within the
_orm.mapped_column()
received byAnnotated
, as this is not
supported with pep-681 Dataclass Transforms. A warning is now emitted when
these parameters are used withinAnnotated
in this way (and they
continue to be ignored). -
[orm] [bug] Fixed issue where calling
_engine.Result.unique()
with a new-style
select()
query in the ORM, where one or more columns yields values
that are of "unknown hashability", typically when using JSON functions like
func.json_build_object()
without providing a type, would fail
internally when the returned values were not actually hashable. The
behavior is repaired to test the objects as they are received for
hashability in this case, raising an informative error message if not. Note
that for values of "known unhashability", such as when the
_types.JSON
or_types.ARRAY
types are used directly, an
informative error message was already raised.The "hashabiltiy testing" fix here is applied to legacy
Query
as
well, however in the legacy case,_engine.Result.unique()
is used for
nearly all queries, so no new warning is emitted here; the legacy behavior
of falling back to usingid()
in this case is maintained, with the
improvement that an unknown type that turns out to be hashable will now be
uniqufied, whereas previously it would not.References: #10459
-
[orm] [bug] Fixed regression in recently revised "insertmanyvalues" feature (likely
issue #9618) where the ORM would inadvertently attempt to
interpret a non-RETURNING result as one with RETURNING, in the case where
theimplicit_returning=False
parameter were applied to the mapped
Table
, indicating that "insertmanyvalues" cannot be used if the
primary key values are not provided.References: #10453
-
[orm] [bug] Fixed bug where ORM
_orm.with_loader_criteria()
would not apply
itself to a_sql.Select.join()
where the ON clause were given as a
plain SQL comparison, rather than as a relationship target or similar.References: #10365
-
[orm] [bug] Fixed issue where
Mapped
symbols likeWriteOnlyMapped
andDynamicMapped
could not be correctly resolved when referenced
as an element of a sub-module in the given annotation, assuming
string-based or "future annotations" style annotations.References: #10412
-
[orm] [bug] Fixed issue with
__allow_unmapped__
declarative option
where types that were declared using collection types such as
list[SomeClass]
vs. the typing constructList[SomeClass]
would fail to be recognized correctly. Pull request courtesy
Pascal Corpet.References: #10385
engine
-
[engine] [bug] Fixed issue within some dialects where the dialect could incorrectly return
an empty result set for an INSERT statement that does not actually return
rows at all, due to artfacts from pre- or post-fetching the primary key of
the row or rows still being present. Affected dialects included asyncpg,
all mssql dialects. -
[engine] [bug] Fixed issue where under some garbage collection / exception scenarios the
connection pool's cleanup routine would raise an error due to an unexpected
set of state, which can be reproduced under specific conditions.References: #10414
sql
-
[sql] [bug] Fixed issue where referring to a FROM entry in the SET clause of an UPDATE
statement would not include it in the FROM clause of the UPDATE statement,
if that entry were nowhere else in the statement; this occurs currently for
CTEs that were added usingUpdate.add_cte()
to provide the desired
CTE at the top of the statement.References: #10408
-
[sql] [bug] Fixed 2.0 regression where the
DDL
construct would no longer
__repr__()
due to the removedon
attribute not being accommodated.
Pull request courtesy Iuri de Silvio.References: #10443
typing
-
[typing] [bug] Fixed typing issue where the argument list passed to
Values
was
too-restrictively tied toList
rather thanSequence
. Pull request
courtesy Iuri de Silvio.References: #10451
-
[typing] [bug] Updates to the codebase to support Mypy 1.6.0.
asyncio
- [asyncio] [bug] Fixed the
_asyncio.AsyncSession.get.execution_options
parameter
which was not being propagated to the underlying_orm.Session
and
was instead being ignored.
mariadb
-
[mariadb] [bug] Modified the mariadb-connector driver to pre-load the
cursor.rowcount
value for all queries, to suit tools such as Pandas that hardcode to
callingResult.rowcount
in this way. SQLAlchemy normally pre-loads
cursor.rowcount
only for UPDATE/DELETE statements and otherwise passes
through to the DBAPI where it can return -1 if no value is available.
However, mariadb-connector does not support invokingcursor.rowcount
after the cursor itself is closed, raising an error instead. Generic test
support has been added to ensure all backends support the allowing
Result.rowcount
to succceed (that is, returning an integer
value with -1 for "not available") after the result is closed.References: #10396
-
[mariadb] [bug] Additional fixes for the mariadb-connector dialect to support UUID data
values in the result in INSERT..RETURNING statements.
mssql
-
[mssql] [bug] Fixed bug where the rule that prevents ORDER BY from emitting within
subqueries on SQL Server was not being disabled in the case where the
select.fetch()
method were used to limit rows in conjunction with
WITH TIES or PERCENT, preventing valid subqueries with TOP / ORDER BY from
being used.References: #10458