Repository navigation
Releases
2.1.9
2.1.9
Released: November 16, 2026
orm
-
[orm] [bug] Fixed issue where deleting the parent object of a one-to-many
relationship configured with_orm.relationship.post_update,
such as the one-to-many side of a bidirectionalpost_update
relationship, would emit the UPDATE that sets the foreign key of the
remaining related objects to NULL twice: once within the regular UPDATE
for those objects and again as the post-update. Only the post-update
UPDATE is now emitted, and it is explicitly ordered to run before the
DELETE of the parent row. Fix approach courtesy 18Abhinav07, with
thanks to canblmz1 for the initial analysis.This change is also backported to: 2.0.58
References: #10936
-
[orm] [bug] Fixed issue where criteria applied to a relationship using
PropComparator.and_()within_orm.selectinload()or
_orm.lazyload(), where the criteria referred to an
_orm.aliased()construct against a subquery that's also the parent
entity of the loader option, would load the related collection using
the bound parameter values within that subquery from the first
execution of the statement, once the statement was retrieved from the
compiled cache.This change is also backported to: 2.0.58
References: #13766
-
[orm] [bug] Fixed issue where loader options nested beneath a
_orm.selectin_polymorphic()option, such as a
_orm.selectinload()for a subclass-specific relationship, would be
silently skipped when the enclosing relationship load was against an
aliased entity such as one produced by_orm.with_polymorphic(), and
a structurally different parent statement using the same loader options
had been executed and cached previously. The selectin polymorphic loader
now uses options from the cached statement in the same way as the
selectin relationship loader already does.This change is also backported to: 2.0.58
References: #13777
-
[orm] [bug] Fixed issue where loader options nested beneath a
_orm.subqueryload()option against an aliased entity, such as
subqueryload(A.bs.of_type(aliased(B))), would be silently skipped
when the statement was served from the compiled cache and was
constructed using a new_orm.aliased()or
_orm.with_polymorphic()object, as is typical when the statement
is built within a function. Nested options such as
_orm.load_only(),_orm.undefer()and
_orm.selectinload()took effect only the first time the statement
was run. The subquery loader now uses options from the cached statement
in the same way as the selectin relationship loader.This change is also backported to: 2.0.58
References: #13779
-
[orm] [bug] Fixed issue where a subclass configured with
_orm.Mapper.polymorphic_loadset to"selectin"would
cause a statement to raiseArgumentErrorwhen the statement
selected from an_orm.aliased()or_orm.with_polymorphic()
construct against the base class, or included another entity, along with
loader options such as_orm.undefer()or_orm.selectinload()
against that construct or entity. The automatic load of the subclass
now leaves out loader options that refer to other entities, which were
already applied by the enclosing statement.This change is also backported to: 2.0.58
References: #13780
-
[orm] [bug] Fixed issue where joined eager loading that wraps the statement in a
subquery, as occurs with LIMIT, OFFSET or DISTINCT, would populate
joined inheritance subclass objects loaded by the main entity with column
values from another row, when the statement also joined to an
_orm.aliased()construct of that same subclass and referred to its
columns, such as in ORDER BY.This change is also backported to: 2.0.58
References: #13798
-
[orm] [bug] [regression] Fixed regression caused by #11226 where a relationship to an
aliased class against a correlated LATERAL subquery, when loaded with
_orm.joinedload()in a query that includes DISTINCT or GROUP BY,
would render the LATERAL without its correlation, returning incorrect
rows. The correlated elements within the LATERAL are now adapted along
with the rest of the eager join when the query is wrapped in a subquery.References: #13783
-
[orm] [bug] Fixed issue where a relationship to an aliased class against a correlated
LATERAL subquery would render the LATERAL without its correlation,
returning incorrect rows, when loaded with_orm.selectinload(),
_orm.subqueryload(),_orm.lazyload()or
_orm.immediateload(), or when joined or joined eager loaded from an
_orm.aliased()parent. The correlated elements within the LATERAL
are now adapted to the parent in each of these cases.References: #13786
-
[orm] [bug] [regression] Fixed regression caused by #13748 where an ORM mapped dataclass
that included a column using_orm.orm_insert_sentinel(), or a
_orm.mapped_column()given aColumnDefaultor
Sequenceobject for_orm.mapped_column.default,
would fail to flush, as the default object itself would be delivered to
the INSERT statement as a parameter value. These objects now apply to
theColumnonly, and are no longer used as the Python-side
default value of the attribute, which now remainsNoneuntil the
object is flushed.References: #13788
engine
-
[engine] [performance] Improved the performance of
_engine.Result.mappings()and
_asyncio.AsyncResult.mappings()when the Cython extensions are in
use. The conversion of each_engine.Rowinto a
_engine.RowMappingis now performed within the compiled
extension, rather than through a Python-level access of the
_engine.Row._mappingattribute, substantially reducing per-row
overhead when fetching rows as mappings.References: #13769
-
[engine] [bug] Fixed issue in
_engine.URL.update_query_pairs()where a key that
was repeated with a sequence of strings as its value would produce a
nested tuple in_engine.URL.query, causing the URL to fail to
render as a string. Passing a sequence of strings as a value, which was
indicated by the type annotations but not documented, is now documented,
and the annotations for_engine.URL.update_query_pairs()and
_engine.URL.update_query_dict()are corrected to accept any
sequence of strings rather than only a list.This change is also backported to: 2.0.58
References: #13770
sql
-
[sql] [bug] Fixed issue in cache key generation where calling
_sql.Select.correlate()or_sql.Select.correlate_except()
withNonewould not change the cache key of the_sql.Select,
so that a statement which disables correlation, or correlates all FROM
objects to enclosing SELECTs, could share a cached SQL string with an
otherwise identical statement using the default auto-correlation
behavior, leading to incorrect SQL being emitted for whichever statement
was executed second.This change is also backported to: 2.0.58
References: #13767
-
[sql] [bug] Fixed issue where a
_sql.select()that refers to aCTE
only within_sql.Select.select_from(), as the left side of
_sql.Select.join_from(), or within a join that was followed by
_sql.Select.with_only_columns(), would not be copied correctly by
_sql.Select.params()orvisitors.cloned_traverse(), such that
the new parameter values could be ignored when the statement was invoked
using the compiled cache, with the original values used instead. On the
2.1 series, where_sql.Select.params()no longer copies the
statement, the issue still applies tovisitors.cloned_traverse()
and similar traversals.Also fixed a related issue where, if a traversal such as
visitors.replacement_traverse()replaced the target of
_sql.Select.join()or_sql.Select.join_from()with a
Join, that join would render twice in the FROM clause of the
resulting statement.This change is also backported to: 2.0.58
References: #13791
-
[sql] [bug] Split the
OperatorClass.COMPARISONinto equality and ordering
operators (OperatorClass.EQUALITYand
OperatorClass.ORDERING).
The types_postgresql.HSTOREand the type used
byFunctionElement.table_valued()now have the
OperatorClass.EQUALITYoperator class.References: #13781
asyncio
-
[asyncio] [bug] The
asyncio.CancelledErrorthat occurs frequently for tasks cancelled
under anyio, where the connection is nonetheless successfully terminated,
is now logged by the connection pool at DEBUG level rather than ERROR.This change is also backported to: 2.0.58
References: #13772
postgresql
- [postgresql] [bug] Fixed issue w...
2.0.58
2.0.58
Released: November 16, 2026
orm
-
[orm] [bug] Fixed issue where deleting the parent object of a one-to-many
relationship configured with_orm.relationship.post_update,
such as the one-to-many side of a bidirectionalpost_update
relationship, would emit the UPDATE that sets the foreign key of the
remaining related objects to NULL twice: once within the regular UPDATE
for those objects and again as the post-update. Only the post-update
UPDATE is now emitted, and it is explicitly ordered to run before the
DELETE of the parent row. Fix approach courtesy 18Abhinav07, with
thanks to canblmz1 for the initial analysis.References: #10936
-
[orm] [bug] Fixed issue where criteria applied to a relationship using
PropComparator.and_()within_orm.selectinload()or
_orm.lazyload(), where the criteria referred to an
_orm.aliased()construct against a subquery that's also the parent
entity of the loader option, would load the related collection using
the bound parameter values within that subquery from the first
execution of the statement, once the statement was retrieved from the
compiled cache.References: #13766
-
[orm] [bug] Fixed issue where loader options nested beneath a
_orm.selectin_polymorphic()option, such as a
_orm.selectinload()for a subclass-specific relationship, would be
silently skipped when the enclosing relationship load was against an
aliased entity such as one produced by_orm.with_polymorphic(), and
a structurally different parent statement using the same loader options
had been executed and cached previously. The selectin polymorphic loader
now uses options from the cached statement in the same way as the
selectin relationship loader already does.References: #13777
-
[orm] [bug] Fixed issue where loader options nested beneath a
_orm.subqueryload()option against an aliased entity, such as
subqueryload(A.bs.of_type(aliased(B))), would be silently skipped
when the statement was served from the compiled cache and was
constructed using a new_orm.aliased()or
_orm.with_polymorphic()object, as is typical when the statement
is built within a function. Nested options such as
_orm.load_only(),_orm.undefer()and
_orm.selectinload()took effect only the first time the statement
was run. The subquery loader now uses options from the cached statement
in the same way as the selectin relationship loader.References: #13779
-
[orm] [bug] Fixed issue where a subclass configured with
_orm.Mapper.polymorphic_loadset to"selectin"would
cause a statement to raiseArgumentErrorwhen the statement
selected from an_orm.aliased()or_orm.with_polymorphic()
construct against the base class, or included another entity, along with
loader options such as_orm.undefer()or_orm.selectinload()
against that construct or entity. The automatic load of the subclass
now leaves out loader options that refer to other entities, which were
already applied by the enclosing statement.References: #13780
-
[orm] [bug] Fixed issue where joined eager loading that wraps the statement in a
subquery, as occurs with LIMIT, OFFSET or DISTINCT, would populate
joined inheritance subclass objects loaded by the main entity with column
values from another row, when the statement also joined to an
_orm.aliased()construct of that same subclass and referred to its
columns, such as in ORDER BY.References: #13798
engine
-
[engine] [bug] Fixed issue in
_engine.URL.update_query_pairs()where a key that
was repeated with a sequence of strings as its value would produce a
nested tuple in_engine.URL.query, causing the URL to fail to
render as a string. Passing a sequence of strings as a value, which was
indicated by the type annotations but not documented, is now documented,
and the annotations for_engine.URL.update_query_pairs()and
_engine.URL.update_query_dict()are corrected to accept any
sequence of strings rather than only a list.References: #13770
sql
-
[sql] [bug] Fixed issue in cache key generation where calling
_sql.Select.correlate()or_sql.Select.correlate_except()
withNonewould not change the cache key of the_sql.Select,
so that a statement which disables correlation, or correlates all FROM
objects to enclosing SELECTs, could share a cached SQL string with an
otherwise identical statement using the default auto-correlation
behavior, leading to incorrect SQL being emitted for whichever statement
was executed second.References: #13767
-
[sql] [bug] Fixed issue where a
_sql.select()that refers to aCTE
only within_sql.Select.select_from(), as the left side of
_sql.Select.join_from(), or within a join that was followed by
_sql.Select.with_only_columns(), would not be copied correctly by
_sql.Select.params()orvisitors.cloned_traverse(), such that
the new parameter values could be ignored when the statement was invoked
using the compiled cache, with the original values used instead. On the
2.1 series, where_sql.Select.params()no longer copies the
statement, the issue still applies tovisitors.cloned_traverse()
and similar traversals.Also fixed a related issue where, if a traversal such as
visitors.replacement_traverse()replaced the target of
_sql.Select.join()or_sql.Select.join_from()with a
Join, that join would render twice in the FROM clause of the
resulting statement.References: #13791
asyncio
-
[asyncio] [bug] The
asyncio.CancelledErrorthat occurs frequently for tasks cancelled
under anyio, where the connection is nonetheless successfully terminated,
is now logged by the connection pool at DEBUG level rather than ERROR.References: #13772
postgresql
-
[postgresql] [bug] Fixed issue where reflection of PostgreSQL columns of type
tsqueryor
regconfigwould returnNullTypeand emit a warning, even
though the_postgresql.TSQUERYand_postgresql.REGCONFIG
types are provided by the PostgreSQL dialect. These types are now mapped
for reflection in the same way as_postgresql.TSVECTOR. Pull
request courtesy Lushiyao5.References: #13762
2.1.8
2.1.8
Released: November 3, 2026
general
-
[general] [change] All files published to PyPI for a release, including the source
distribution as well as all wheels, are now uploaded using PyPI's trusted
publishing mechanism from SQLAlchemy's GitHub Actions workflow, and include
a PEP 740 attestation, so that every file in a release carries
provenance information. Previously, the source distribution and some
wheels were uploaded without an attestation, which caused PyPI to display
provenance warnings for recent releases.This change is also backported to: 2.0.57
References: #13759
2.0.57
2.0.57
Released: November 3, 2026
general
-
[general] [change] All files published to PyPI for a release, including the source
distribution as well as all wheels, are now uploaded using PyPI's trusted
publishing mechanism from SQLAlchemy's GitHub Actions workflow, and include
a PEP 740 attestation, so that every file in a release carries
provenance information. Previously, the source distribution and some
wheels were uploaded without an attestation, which caused PyPI to display
provenance warnings for recent releases.References: #13759
2.1.7
2.1.7
Released: November 3, 2026
orm
-
[orm] [feature] Added
_orm.SessionTransaction.connectionsand
_orm.SessionTransaction.bound_connection(), which return the
connections a_orm.SessionTransactionhas already acquired,
without acquiring a new one. This allows, for example, checking whether
any connection in the transaction has been invalidated before emitting
further SQL. A SAVEPOINT transaction returned by
_orm.Session.begin_nested()reports only the connections used
within that SAVEPOINT; the root transaction returned by
_orm.Session.get_transaction()reports all connections. The same
accessors are available on_asyncio.AsyncSessionTransaction,
returning_asyncio.AsyncConnectionobjects. Pull request
courtesy Artur Shiriev.References: #13685
-
[orm] [bug] An informative
InvalidRequestErroris now raised when more than
onePropComparator.of_type()loader option is applied along the
same relationship using targets of differing classes, such as two
_orm.aliased()constructs against different subclasses, which
previously failed with a bareAssertionErrorduring compilation.
These options can't be combined since each target brings its own aliased
copy of the base table; to load multiple subclasses along a single
relationship, a single_orm.with_polymorphic()object that includes
all of the target classes should be used.This change is also backported to: 2.0.56
References: #13751
-
[orm] [bug] Fixed issue where criteria applied to a relationship using
PropComparator.and_()within_orm.selectinload()or
_orm.lazyload()would not be parenthesized against the
relationship's join condition when the enclosing statement was retrieved
from the compiled cache, so that criteria consisting of an
_sql.or_()would render asa = ? AND b = ? OR c = ?. For
_orm.lazyload(), this could load rows belonging to other parents into
the collection. The issue typically appeared as a race condition in
multithreaded applications, but could also occur within a single thread
depending on the order in which statements were executed.This change is also backported to: 2.0.56
References: #13753
-
[orm] [bug] [regression] Fixed regression caused by #13070 where using two or more
orm.with_loader_criteria()options for different entities, where
the criteria of each referred to the other entity, such as by using
RelationshipProperty.Comparator.any()and
RelationshipProperty.Comparator.has(), would fail with a
RecursionErrorwhen compiling. A loader criteria option is now
no longer applied to a SELECT that's nested at any level within its own
criteria; previously this was only checked for the immediate SELECT
within the criteria. This also repairs the sameRecursionErrorfor
criteria which refer to each other using explicit subqueries, an issue
also present in the 2.0 series. No backport is planned at the moment as
this is an unusual use case.References: #13714
-
[orm] [bug] Fixed issue where
_orm.Session.merge_all()did not disable autoflush
while merging, as_orm.Session.merge()does, so that a lazy load
emitted during the merge cascade could autoflush a partially merged
object, leading to integrity errors or other failures.References: #13715
-
[orm] [bug] [regression] Fixed regression caused by #12168 where a collection-based
_orm.relationship()using the
orm_declarative_native_dataclassesfeature with a custom
_orm.relationship.collection_classsuch as
_orm.attribute_keyed_dict()would raise an error if
_orm.relationship.default_factorywere set to the plain
dict,listorsettype that the collection class is based on,
such asdefault_factory=dictfor_orm.attribute_keyed_dict().
The plain collection type is now accepted as the
_orm.relationship.default_factoryin addition to the exact
collection class.References: #13718
-
[orm] [bug] [regression] Fixed regression caused by #5987 where the
selectinload()
loader strategy, when loading a many-to-many relationship against an
aliased target, such as when usingPropComparator.of_type()with a
single-inheritance subclass or analiased()construct, would render
the join between the association table and the aliased target using the
unaliased table name, producing invalid SQL.References: #13726
-
[orm] [bug] [regression] Fixed issue where a SAVEPOINT started by
_orm.Session.begin_nested()
would apply execution options to the connection a second time, causing
options such asisolation_levelto raise. Additionally, execution
options passed to_orm.Session.connection()within a SAVEPOINT are
now ignored with a warning if the connection is already present, as
documented, where previously they were applied. -
[orm] [bug] [regression] Fixed regression caused by #12168 where a
_orm.mapped_column()using
_orm.mapped_column.use_existing_columnalong with
_orm.mapped_column.defaultin an
orm_declarative_native_dataclassesmapping would not persist the
given default value. As the existing_schema.Columnfrom the
superclass table is mapped in this case, the default value would not take
effect for INSERT, and the default from the superclass column, if any,
would be used instead. The unit of work now delivers the dataclass
default of an attribute that was never set to the INSERT statement in
those cases where the mapped_schema.Columndoes not supply that
same default, while the attribute continues to remain un-set until the
object is flushed, so that the behaviors established by #12168
are maintained.This includes a behavioral change for an attribute that is set to
None
explicitly, which the ORM treats as the default case for a column that has
a default, as described atsession_forcing_null. Such an attribute
now receives the dataclass default of the subclass, consistent with an
attribute that was never set, where previously the default of the
superclass column would take effect.References: #13748
engine
-
[engine] [bug] Fixed issue where the
_sa.create_engine.hide_parameters
parameter was not honored when logging bound parameters for "side"
statements that are executed separately from the main statement, such as
pre-executed SQL expression column defaults, so that parameter values were
written to the log in plain form. These parameters are now hidden in the
same way as those of the main statement.This change is also backported to: 2.0.56
References: #13724
-
[engine] [bug] Fixed issue where event listeners established on the
_engine.Connectionclass itself, such as
_events.ConnectionEvents.before_execute(), would not be invoked
for connections procured from an_engine.Enginethat did not
itself have any event listeners associated with it.This change is also backported to: 2.0.56
References: #13743
-
[engine] [bug] Fixed issue where
URL.difference_update_query()would not remove
any parameters when passed a generator or other single-use iterable, as
the iterable was consumed twice internally. Pull request courtesy
Huang-404-Q.This change is also backported to: 2.0.56
References: #13757
-
[engine] [bug] [regression] Fixed regression where a checked-out pool connection that was garbage
collected as part of a reference cycle would not be returned to the pool
on Python 3.15, permanently consuming a slot in the pool. This occurred
because Python 3.15 changed the garbage collector to clear weak references
that have no callback only after weak reference callbacks have run, which
interfered with the pool'sweakref.finalize()based cleanup introduced
in 2.1.0rc2. An ORM_orm.Sessionor_engine.Connection
that was dropped without being closed while in a transaction was affected.References: #13738
sql
- [sql] [bug] [oracle] [postgresql] Reworked the validation applied to the keyword phrases accepted by the
_schema.ForeignKeyConstraint.ondelete,
_schema.ForeignKeyConstraint.onupdate,
_schema.ForeignKeyConstraint.initiallyand
_schema.ForeignKeyConstraint.matchparameters so that it is
applied consistently on all backends. Previously, some of these phrases
were checked against a fixed list of keywords, which rejected
backend-specific syntaxes, while others were not validated at all,
includingMATCHon all backends,ON DELETEon the Oracle dialect,
and the column list accepted by PostgreSQL forSET NULL/ `SET
DEFAULT...
2.0.56
2.0.56
Released: November 3, 2026
orm
-
[orm] [bug] Fixed issue where a
Sessionflush that replaced an expired
object in the identity map with a newly flushed object of the same
primary key would emit a SELECT to refresh the expired object, solely in
order to determine whether to emit an "Identity map already had an
identity" warning. This could occur when a row loaded within a
transaction is rolled back and its primary key value is subsequently
reused, and could lead to anAttributeErrorif the expired object
were garbage collected during that load. The check now emits no SQL, and
an expired object that is replaced in this way no longer causes the
warning to be emitted.References: #13711
-
[orm] [bug] An informative
InvalidRequestErroris now raised when more than
onePropComparator.of_type()loader option is applied along the
same relationship using targets of differing classes, such as two
_orm.aliased()constructs against different subclasses, which
previously failed with a bareAssertionErrorduring compilation.
These options can't be combined since each target brings its own aliased
copy of the base table; to load multiple subclasses along a single
relationship, a single_orm.with_polymorphic()object that includes
all of the target classes should be used.References: #13751
-
[orm] [bug] Fixed issue where criteria applied to a relationship using
PropComparator.and_()within_orm.selectinload()or
_orm.lazyload()would not be parenthesized against the
relationship's join condition when the enclosing statement was retrieved
from the compiled cache, so that criteria consisting of an
_sql.or_()would render asa = ? AND b = ? OR c = ?. For
_orm.lazyload(), this could load rows belonging to other parents into
the collection. The issue typically appeared as a race condition in
multithreaded applications, but could also occur within a single thread
depending on the order in which statements were executed.References: #13753
orm extensions
-
[bug] [orm extensions] Fixed an issue in the
instrumentation_toplevelextension where
unrelated classes inheriting fromtyping.Genericcould incorrectly
raise aTypeErrorwhen using different instrumentation implementations.
Pull request courtesy TomasCaruso10.References: #13680
engine
-
[engine] [bug] Fixed issue where the
_sa.create_engine.hide_parameters
parameter was not honored when logging bound parameters for "side"
statements that are executed separately from the main statement, such as
pre-executed SQL expression column defaults, so that parameter values were
written to the log in plain form. These parameters are now hidden in the
same way as those of the main statement.References: #13724
-
[engine] [bug] Fixed issue where event listeners established on the
_engine.Connectionclass itself, such as
_events.ConnectionEvents.before_execute(), would not be invoked
for connections procured from an_engine.Enginethat did not
itself have any event listeners associated with it.References: #13743
-
[engine] [bug] Fixed issue where
URL.difference_update_query()would not remove
any parameters when passed a generator or other single-use iterable, as
the iterable was consumed twice internally. Pull request courtesy
Huang-404-Q.References: #13757
sql
-
[sql] [bug] Fixed issues in cache key generation involving the DML constructs
Insert,UpdateandDelete. The
Insert.from_select.include_defaults,
UpdateBase.return_defaults()and
UpdateBase.return_defaults.supplemental_cols
parameters/attributes are now considered as part of the cache key. -
[sql] [bug] Fixed issue where the individual bound parameters generated for an
"expanding" parameter, such as that of an IN expression, at statement
execution time could take on the same name as another bound parameter in
the same statement, causing the value of the other parameter to be
silently replaced with that of an element of the IN list. Names are now
disambiguated from one another in this scenario.References: #13695
-
[sql] [bug] [oracle] [postgresql] Reworked the validation applied to the keyword phrases accepted by the
_schema.ForeignKeyConstraint.ondelete,
_schema.ForeignKeyConstraint.onupdate,
_schema.ForeignKeyConstraint.initiallyand
_schema.ForeignKeyConstraint.matchparameters so that it is
applied consistently on all backends. Previously, some of these phrases
were checked against a fixed list of keywords, which rejected
backend-specific syntaxes, while others were not validated at all,
includingMATCHon all backends,ON DELETEon the Oracle dialect,
and the column list accepted by PostgreSQL forSET NULL/SET DEFAULT, allowing arbitrary text to be rendered into DDL. These phrases
are now accepted as any sequence of SQL keywords, leaving it to the
database to determine if the keywords are valid, and a
CompileErroris raised for a phrase that contains other
characters such as punctuation or quotes. On PostgreSQL, the column list
forSET NULL/SET DEFAULTis accepted as a comma-separated list
of plain or double-quoted column names. Pull request courtesy
basavaraj-sm05.References: #13727
asyncio
-
[asyncio] [bug] Fixed issue where calling
_asyncio.AsyncResult.unique()or
_asyncio.AsyncResult.columns()on an_asyncio.AsyncResult
would have no effect on a subsequent call to
_asyncio.AsyncResult.scalars()or
_asyncio.AsyncResult.mappings(), as the resulting
_asyncio.AsyncScalarResultor
_asyncio.AsyncMappingResultwas built from the underlying
synchronous result, which did not include those modifications. Unique
filtering and column selection are now carried over in the same way as for
_engine.Result.scalars()and_engine.Result.mappings(). Among
other things, this allows_asyncio.AsyncSession.stream()to be used
with a joined eager load against a collection, followed by
.unique().scalars(), which would previously raise an error indicating
that_asyncio.AsyncResult.unique()must be invoked.References: #13688
-
[asyncio] [bug] Fixed issue where the
_asyncio.AsyncResult.freeze()method would
fail to fetch rows from the result, producing a
_engine.FrozenResultthat would raiseTypeErrorwhen invoked
for a Core result, or raisingAttributeErrorimmediately for an ORM
result that returns a single entity per row. The method now fully
fetches all rows from the async cursor, honoring
_asyncio.AsyncResult.unique()and
_asyncio.AsyncResult.columns()in the same way as the synchronous
_engine.Result.freeze()method.References: #13689
-
[asyncio] [bug] Fixed regression caused by #12710 where a cancellation received
by_asyncio.AsyncConnection.close()was not handled properly,
leaving the_asyncio.AsyncConnectionin an inconsistent state
that could interfere with connections subsequently checked out from the
pool. The connection is now fully closed in this case.References: #13699
-
[asyncio] [bug] Fixed issue where an asyncio cancellation delivered to a task waiting for
a connection fromAsyncAdaptedQueuePoolwould be lost on Python
3.11, if a connection were returned to the pool in the same event loop
iteration in which the task was cancelled. The task would receive the
connection and continue running as though it had not been cancelled.
This was due to a known issue inasyncio.wait_for()which is fixed in
Python 3.12; on Python 3.11, the pool now usesasyncio.timeout()in
place ofasyncio.wait_for()when waiting for a connection. The issue
remains on Python 3.10 and earlier, whereasyncio.timeout()is not
available.References: #13749
mysql
-
[mysql] [bug] Fixed issue where backslashes in the values of a
mysql.ENUMor
mysql.SETtype were not escaped when rendered in DDL, leading to
incorrect values or a malformed statement under MySQL's default
sql_mode. Backslashes are now escaped in the same way as for other
string literals, unlessNO_BACKSLASH_ESCAPESis in effect. Pull
request courtesy dxbjavid.References: #13466
mssql
- [mssql] [bug] [reflection] Reflection of SQL Server local temporary tables, such as
#tmp, now
supports tables of the same name existing in multiple sessions at once,
each session reflecting its own table. Previously, the table was located
without the use of theobject_id()function, which is what limits the
lookup to the current session, so that same-named tables in other sessions
would interfere wit...
2.1.6
2.1.6
Released: October 21, 2026
orm
-
[orm] [bug] Fixed issue where a
Sessionflush that replaced an expired
object in the identity map with a newly flushed object of the same
primary key would emit a SELECT to refresh the expired object, solely in
order to determine whether to emit an "Identity map already had an
identity" warning. This could occur when a row loaded within a
transaction is rolled back and its primary key value is subsequently
reused, and could lead to anAttributeErrorif the expired object
were garbage collected during that load. The check now emits no SQL, and
an expired object that is replaced in this way no longer causes the
warning to be emitted.This change is also backported to: 2.0.56
References: #13711
-
[orm] [bug] [regression] Fixed regression caused by #13070 where using more than one
orm.with_loader_criteria()option for the same entity, where the
criteria made use of correlated subqueries referring to that entity, would
fail with aRecursionErrorwhen compiling.References: #13701
-
[orm] [bug] [regression] Fixed regression caused by the new implementation of
.params()for
statements introduced in #7066, where parameter values passed to
the.params()method of an ORM statement created using
Select.from_statement()would not be applied when the statement
was compiled without the compiled statement cache, such as when the cache
was disabled or when the statement was stringified directly, leading to
an error that a value is required for the bound parameter.References: #13709
orm extensions
-
[bug] [orm extensions] Fixed an issue in the
instrumentation_toplevelextension where
unrelated classes inheriting fromtyping.Genericcould incorrectly
raise aTypeErrorwhen using different instrumentation implementations.
Pull request courtesy TomasCaruso10.This change is also backported to: 2.0.56
References: #13680
engine
-
[engine] [usecase] Added
make_url.keep_blank_valuesand
URL.update_query_string.keep_blank_valuesparameters, which
when set to True retain query string parameters with blank values such as
key=in theURL.querydictionary as empty strings. This allows
aURLwith empty-string query values to round trip through
URL.render_as_string()andmake_url(). The default behavior
of omitting blank values is unchanged, as dialects may not accept an empty
string for query parameters that are coerced to other types.References: #13697
sql
-
[sql] [bug] Fixed issues in cache key generation involving the DML constructs
Insert,UpdateandDelete. The
Insert.from_select.include_defaults,
UpdateBase.return_defaults()and
UpdateBase.return_defaults.supplemental_cols
parameters/attributes are now considered as part of the cache key.This change is also backported to: 2.0.56
-
[sql] [bug] Fixed issue where the individual bound parameters generated for an
"expanding" parameter, such as that of an IN expression, at statement
execution time could take on the same name as another bound parameter in
the same statement, causing the value of the other parameter to be
silently replaced with that of an element of the IN list. Names are now
disambiguated from one another in this scenario.This change is also backported to: 2.0.56
References: #13695
asyncio
-
[asyncio] [bug] Fixed issue where calling
_asyncio.AsyncResult.unique()or
_asyncio.AsyncResult.columns()on an_asyncio.AsyncResult
would have no effect on a subsequent call to
_asyncio.AsyncResult.scalars()or
_asyncio.AsyncResult.mappings(), as the resulting
_asyncio.AsyncScalarResultor
_asyncio.AsyncMappingResultwas built from the underlying
synchronous result, which did not include those modifications. Unique
filtering and column selection are now carried over in the same way as for
_engine.Result.scalars()and_engine.Result.mappings(). Among
other things, this allows_asyncio.AsyncSession.stream()to be used
with a joined eager load against a collection, followed by
.unique().scalars(), which would previously raise an error indicating
that_asyncio.AsyncResult.unique()must be invoked.This change is also backported to: 2.0.56
References: #13688
-
[asyncio] [bug] Fixed issue where the
_asyncio.AsyncResult.freeze()method would
fail to fetch rows from the result, producing a
_engine.FrozenResultthat would raiseTypeErrorwhen invoked
for a Core result, or raisingAttributeErrorimmediately for an ORM
result that returns a single entity per row. The method now fully
fetches all rows from the async cursor, honoring
_asyncio.AsyncResult.unique()and
_asyncio.AsyncResult.columns()in the same way as the synchronous
_engine.Result.freeze()method.This change is also backported to: 2.0.56
References: #13689
-
[asyncio] [bug] Fixed regression caused by #12710 where a cancellation received
by_asyncio.AsyncConnection.close()was not handled properly,
leaving the_asyncio.AsyncConnectionin an inconsistent state
that could interfere with connections subsequently checked out from the
pool. The connection is now fully closed in this case.This change is also backported to: 2.0.56
References: #13699
mysql
-
[mysql] [bug] Fixed issue where backslashes in the values of a
mysql.ENUMor
mysql.SETtype were not escaped when rendered in DDL, leading to
incorrect values or a malformed statement under MySQL's default
sql_mode. Backslashes are now escaped in the same way as for other
string literals, unlessNO_BACKSLASH_ESCAPESis in effect. Pull
request courtesy dxbjavid.This change is also backported to: 2.0.56
References: #13466
2.1.5
2.1.5
Released: October 16, 2026
orm
-
[orm] [feature] Added the
_orm.Unmappedannotation and the
_orm.unmapped_column()construct, providing a declarative-compatible
approach to having "excluded" columns in a Declarative model, that is,
columns that are part of the_schema.Tablebut are not mapped,
replacing the use of_orm.Mapper.exclude_propertiesfor this
purpose when using a Declarative mapping.References: #13650
-
[orm] [bug] [regression] Fixed regression caused by #11917 in version 2.0.36 where an ORM
enabled_sql.update()using WHERE criteria which matched more than
one object present in the_orm.Sessionwould expire server-side
onupdate columns, as well as columns that were SET to a SQL expression, on
only one of the matched objects, leaving the remaining objects with stale
values for those attributes. The columns are now expired for all matched
objects.This change is also backported to: 2.0.55
References: #13675
-
[orm] [deprecated] Using the
_orm.Mapper.exclude_propertiesor
_orm.Mapper.include_propertiesparameters on a Declarative
mapping to exclude attributes that are declared on the class, such as with
_orm.mapped_column(), is deprecated and now emits a deprecation
warning. This use was never supported, and depending on the arguments
passed to_orm.mapped_column(), the attribute could remain mapped
regardless; in particular, as of 2.1 this includes ORM mapped dataclasses
where_orm.mapped_column.defaultis present. The new
_orm.unmapped_column()construct should be used instead. Excluding
columns that are present only in the_schema.Table, such as those
from__table__,__table_args__or table reflection, is not
affected.References: #13650
schema
-
[schema] [bug] Fixed issue where dialect-specific keyword arguments established on a
ForeignKeyConstraint,ForeignKeyor
CheckConstraint, such aspostgresql_not_valid, were not
carried along to the copy of the constraint produced by
Table.to_metadata(), so that the copiedTablewould
generate DDL without these options. The fix for #5276 had
established this behavior forColumn,
PrimaryKeyConstraintandUniqueConstraintonly.This change is also backported to: 2.0.55
References: #13677
asyncio
-
[asyncio] [bug] Fixed issue where a task that was cancelled a second time while the
connection pool was closing an asyncio connection invalidated by the
first cancellation, such as one received while a statement was
executing, would leave the closed connection in place in the pool, where
it would be handed out to the next checkout and fail upon first use.
The pool now discards the connection in all cases once a close has been
attempted. This condition occurs unconditionally for tasks cancelled by
an AnyIO cancel scope, which delivers the cancellation repeatedly until
the task exits the scope.This change is also backported to: 2.0.55
References: #13673
-
[asyncio] [bug] Fixed regression caused by #13548 where an asyncio cancellation
delivered while the pool was closing a connection stranded by an
exception raised within the_events.PoolEvents.connect()event
handler would be suppressed, with the original exception raised in its
place. The task would then not end as cancelled, and code that catches
ordinary exceptions in order to retry would continue running after it
had been cancelled. TheCancelledErroris now propagated.As part of this change, a variety of other cancellation scenarios were
caught and repaired.This change is also backported to: 2.0.55
References: #13678
2.0.55
2.0.55
Released: October 16, 2026
orm
-
[orm] [bug] Fixed issue in Annotated Declarative where an annotation naming an
undefined symbol, where the annotation is not wrapped in
_orm.Mapped, would raiseTypeErrorrather than the expected
MappedAnnotationErrorwhen running under Python 3.14 without
from __future__ import annotationsin effect. Under PEP 649, such
an annotation is delivered as aForwardRefrather than a string, a
form which was not accommodated by the check that determines whether an
unresolvable annotation was intended to be mapped.References: #13602
-
[orm] [bug] [regression] Fixed regression caused by #11917 in version 2.0.36 where an ORM
enabled_sql.update()using WHERE criteria which matched more than
one object present in the_orm.Sessionwould expire server-side
onupdate columns, as well as columns that were SET to a SQL expression, on
only one of the matched objects, leaving the remaining objects with stale
values for those attributes. The columns are now expired for all matched
objects.References: #13675
orm extensions
-
[bug] [orm extensions] Fixed issue in the
mutable_toplevelextension where the in-place
|=operator onMutableDictand the in-place*=operator
onMutableListdid not emit change events, so that the
modification was not detected and was not persisted on the next flush.
These operators now invokeMutable.changed()in the same way as
the in-place set operators ofMutableSetand the+=
operator ofMutableList.References: #13643
engine
-
[engine] [bug] [regression] Fixed regression from the 1.4 series where the DBAPI cursor used for a
compiled statement that returns no rows, which includes DDL constructs
such asCreateTableandDropTableas well as the
SAVEPOINT, ROLLBACK TO SAVEPOINT and RELEASE SAVEPOINT statements emitted
by_engine.Connection.begin_nested(), was not closed after
execution, and was instead left to be released when garbage collected.
The cursor is now closed immediately, as was the case in 1.3 and as is
already the case for INSERT, UPDATE, DELETE and_sql.text()
statements.References: #13640
-
[engine] [bug] Fixed issue in the
_engine.Connection.execution_options.logging_tokenoption
where setting the value toNoneor another false value would raise
AttributeErrorif a logging token had not already been established on
that_engine.Connection, such as on a newly checked out
connection, when the option was set at the_engine.Enginelevel,
or when the token was reset toNonemore than once. Regression
introduced in 2.0.30 as part of #11210.References: #13641
sql
-
[sql] [performance] Added instance-level caching to the "comparator factory" method of the
TypeDecoratorclass. This attribute is used in most SQL
comparison operations and was generating a new class on the fly each time
it was called. Special steps have been taken to allow this class to be
cached while still allowing for pickling of theTypeDecorator
itself.References: #13617
-
[sql] [bug] Fixed an additional race condition related to those fixed as part of
#12302, where concurrent access to the
FromClause.primary_keyorFromClause.foreign_keys
collections on a newly createdAliasorSubquery
could raise anAssertionErrorif another thread was in the midst of
generating these collections.References: #12302
-
[sql] [bug] Fixed issue where literal text within a SQL statement that resembled a
pyformatbound parameter, such as%(name)s, would be rewritten as a
bound parameter placeholder when compiling for a dialect using a
positional paramstyle such asqmark,format,numericor
numeric_dollar. This would occur for string values rendered with the
literal_bindscompiler option, as well as for literal text within
_sql.text()or_sql.literal_column()constructs, leading to a
SQL statement that silently compared against a different value, or that
raised aKeyErrorfor numeric paramstyles. This was a regression
caused by the change in the 2.0 series where statements for positional
paramstyles are first compiled using named parameters, which are then
converted to positional placeholders.References: #13609
-
[sql] [bug] The rendering of bound parameters within a
_sql.text()construct no
longer considers the$character to be part of a bound parameter name,
matching the parsing already performed by_sql.text()itself when
the construct is created. Previously, a string such as:foo$barwould
be rendered as a single bound parameter namedfoo$bar, for which a
value could not be passed, and which would fail when executed. The
string is now rendered as the bound parameterfoofollowed by the
literal text$bar. Additionally,_sql.text()no longer
establishes a spurious bound parameter from a name that is immediately
followed by a colon, such asthifor the string:this:thator
vafor the string:val::int; these strings are not rendered as
bound parameters, and_sql.text()now uses the same parsing as the
compiler to determine this.References: #13609
-
[sql] [bug] Fixed issue where the
UpdateBase.return_defaults.supplemental_colsparameter of
UpdateBase.return_defaults()was not included in the cache key of
anInsertorUpdateconstruct, causing a statement
that used this parameter to share a cached compiled form with an otherwise
identical statement that did not, or that used different supplemental
columns. This would cause the supplemental RETURNING rows to be missing
or incorrect depending on which form of the statement was compiled first.
schema
-
[schema] [bug] Fixed issue where dialect-specific keyword arguments established on a
ForeignKeyConstraint,ForeignKeyor
CheckConstraint, such aspostgresql_not_valid, were not
carried along to the copy of the constraint produced by
Table.to_metadata(), so that the copiedTablewould
generate DDL without these options. The fix for #5276 had
established this behavior forColumn,
PrimaryKeyConstraintandUniqueConstraintonly.References: #13677
asyncio
-
[asyncio] [bug] Fixed issue where cancelling a task while an asyncio context manager
such as_asyncio.AsyncConnectionor_asyncio.AsyncSession
was closing on exit would allow the task to complete while the close
continued in the background. An application that disposed of the
engine at that point, as is typical at shutdown, would have the
connection returned to the disposed pool afterwards, where nothing
would close it. The context manager now waits for the close to complete
before propagating the cancellation.Also fixed related issues in the connection pool where a cancellation
received while a connection was being reset on return to the pool, or a
second cancellation received while the pool was cleaning up after a
first cancellation during checkout, would prevent the connection's slot
from being returned to the pool, reducing the pool's capacity until the
connection object was garbage collected, or permanently in the latter
case. -
[asyncio] [bug] Fixed issue where a task that was cancelled a second time while the
connection pool was closing an asyncio connection invalidated by the
first cancellation, such as one received while a statement was
executing, would leave the closed connection in place in the pool, where
it would be handed out to the next checkout and fail upon first use.
The pool now discards the connection in all cases once a close has been
attempted. This condition occurs unconditionally for tasks cancelled by
an AnyIO cancel scope, which delivers the cancellation repeatedly until
the task exits the scope.References: #13673
-
[asyncio] [bug] Fixed regression caused by #13548 where an asyncio cancellation
delivered while the pool was closing a connection stranded by an
exception raised within the_events.PoolEvents.connect()event
handler would be suppressed, with the original exception raised in its
place. The task would then not end as cancelled, and code that catches
ordinary exceptions in order to retry would continue running after it
had been cancelled. TheCancelledErroris now propagated.As part of this change, a variety of other cancellation scenarios were
caught and repaired.References: #13678
postgresql
- [postgresql] [bug] [reflection] Fixed issue in PostgreSQL ref...
2.1.4
2.1.4
Released: October 7, 2026
orm
-
[orm] [bug] [regression] Fixed regression caused by #13333 where assigning a
MetaDataobject to themetadataattribute of a mapped
Declarative class, in order to place that class'sTablein a
MetaDatacollection other than that of the
_orm.registry, would emit a warning that the attribute name
metadatashould be left reserved. The warning is now emitted only
when themetadataattribute is assigned to an object other than a
MetaData.References: #13659
engine
-
[engine] [bug] [regression] Fixed regression from the 1.4 series where the DBAPI cursor used for a
compiled statement that returns no rows, which includes DDL constructs
such asCreateTableandDropTableas well as the
SAVEPOINT, ROLLBACK TO SAVEPOINT and RELEASE SAVEPOINT statements emitted
by_engine.Connection.begin_nested(), was not closed after
execution, and was instead left to be released when garbage collected.
The cursor is now closed immediately, as was the case in 1.3 and as is
already the case for INSERT, UPDATE, DELETE and_sql.text()
statements.This change is also backported to: 2.0.55
References: #13640
-
[engine] [bug] Fixed issue in the
_engine.Connection.execution_options.logging_tokenoption
where setting the value toNoneor another false value would raise
AttributeErrorif a logging token had not already been established on
that_engine.Connection, such as on a newly checked out
connection, when the option was set at the_engine.Enginelevel,
or when the token was reset toNonemore than once. Regression
introduced in 2.0.30 as part of #11210.This change is also backported to: 2.0.55
References: #13641
-
[engine] [bug] [regression] Fixed regression where iterating a
Resultdirectly would create
reference cycles that prevented theResultalong with the DBAPI
cursor from being freed immediately, instead relying upon cyclic GC to free
it; also fixed a similar issue when using scalar-returning methods such as
Result.scalars(). The issues were introduced as part of a 2.1
refactoring ofResultinto Cython code.References: #13639
-
[engine] [bug] Fixed issue where an exception raised by the rollback performed within
_engine.Connection.close(), which was not otherwise classified as a
disconnect, would leave the_engine.Connectionopen and its
pooled DBAPI connection checked out, emitting a warning when later
garbage collected; for an asyncio driver, the connection could not be
closed at that point and was leaked. The DBAPI connection is now
returned to the pool, which resets it as usual, invalidating it if that
reset fails as well, and the original exception is raised.References: #13657
sql
-
[sql] [bug] Fixed issue where the
UpdateBase.return_defaults.supplemental_colsparameter of
UpdateBase.return_defaults()was not included in the cache key of
anInsertorUpdateconstruct, causing a statement
that used this parameter to share a cached compiled form with an otherwise
identical statement that did not, or that used different supplemental
columns. This would cause the supplemental RETURNING rows to be missing
or incorrect depending on which form of the statement was compiled first.This change is also backported to: 2.0.55
-
[sql] [bug] [regression] Fixed regression where stringifying a statement that includes the
_functions.aggregate_stringsfunction, such as viastr(),
would raiseTypeError. Additionally, compiling the function with the
default dialect or with a third party dialect that doesn't provide its own
rendering for this function now raisesCompileErrorrather than
TypeError.References: #13642
postgresql
-
[postgresql] [bug] Fixed regression where copying a
_postgresql.DOMAINdatatype,
as occurs when usingTypeEngine.copy(),Table.to_metadata(),
or when aColumnreferring to a_postgresql.DOMAINis
placed on a declarative mixin, would drop the
_postgresql.DOMAIN.collation,
_postgresql.DOMAIN.default,
_postgresql.DOMAIN.constraint_name,
_postgresql.DOMAIN.not_nulland
_postgresql.DOMAIN.checkparameters, causing the
CREATE DOMAINstatement emitted for the copied type to omit these
elements. The regression was introduced in version 2.0.42.Additionally, copies of
_postgresql.ENUMnow retain the
_types.Enum.sort_key_function,
_types.Enum.create_constraintand
_types.Enum.lengthparameters, and copies of
_types.Enumnow retain the
_types.Enum.sort_key_functionparameter, all of which were
previously reset to their default values.This change is also backported to: 2.0.55
References: #13644
-
[postgresql] [bug] [regression] Fixed regression in the asyncpg dialect where a failure to start a
transaction, such as when an asyncpg connection is used from a different
event loop than the one it was created on, would leave the failed asyncpg
transaction in place, so that the subsequent rollback raised an
InterfaceErrorthat masked the original error.References: #13657
mssql
-
[mssql] [bug] Fixed issue where the Python true division operator
/would truncate
the fractional part of the divisor on SQL Server when the divisor's type
was not numeric, such as when using a SQL function likeNULLIF()that
has no known return type. The divisor was rendered asCAST(... AS NUMERIC), which on SQL Server implies a scale of zero; the divisor is
now rendered as(... + 0.0), the same approach used by the SQLite
dialect, which promotes it to a decimal value without truncation.
Pull request courtesy James Guthrie.This change is also backported to: 2.0.55
References: #13631
misc
-
[bug] [ext] Fixed issue in the
mutable_toplevelextension where the in-place
|=operator onMutableDictand the in-place*=operator
onMutableListdid not emit change events, so that the
modification was not detected and was not persisted on the next flush.
These operators now invokeMutable.changed()in the same way as
the in-place set operators ofMutableSetand the+=
operator ofMutableList.This change is also backported to: 2.0.55
References: #13643