Releases: sqlalchemy/sqlalchemy
2.0.44
2.0.44
Released: October 10, 2025
platform
- [platform] [bug] Unblocked automatic greenlet installation for Python 3.14 now that
there are greenlet wheels on pypi for python 3.14.
orm
-
[orm] [usecase] The way ORM Annotated Declarative interprets Python PEP 695 type aliases
inMapped[]
annotations has been refined to expand the lookup scheme. A
PEP 695 type can now be resolved based on either its direct presence in
_orm.registry.type_annotation_map
or its immediate resolved
value, as long as a recursive lookup across multiple PEP 695 types is
not required for it to resolve. This change reverses part of the
restrictions introduced in 2.0.37 as part of #11955, which
deprecated (and disallowed in 2.1) the ability to resolve any PEP 695
type that was not explicitly present in
_orm.registry.type_annotation_map
. Recursive lookups of
PEP 695 types remains deprecated in 2.0 and disallowed in version 2.1,
as do implicit lookups ofNewType
types without an entry in
_orm.registry.type_annotation_map
.Additionally, new support has been added for generic PEP 695 aliases that
refer to PEP 593Annotated
constructs containing
_orm.mapped_column()
configurations. See the sections below for
examples.References: #12829
-
[orm] [bug] Fixed a caching issue where
_orm.with_loader_criteria()
would
incorrectly reuse cached bound parameter values when used with
_sql.CompoundSelect
constructs such as_sql.union()
. The
issue was caused by the cache key for compound selects not including the
execution options that are part of the_sql.Executable
base class,
which_orm.with_loader_criteria()
uses to apply its criteria
dynamically. The fix ensures that compound selects and other executable
constructs properly include execution options in their cache key traversal.References: #12905
engine
-
[engine] [bug] Implemented initial support for free-threaded Python by adding new tests
and reworking the test harness to include Python 3.13t and Python 3.14t in
test runs. Two concurrency issues have been identified and fixed: the first
involves initialization of the.c
collection on aFromClause
, a
continuation of #12302, where an optional mutex under
free-threading is added; the second involves synchronization of the pool
"first_connect" event, which first received thread synchronization in
#2964, however under free-threading the creation of the mutex
itself runs under the same free-threading mutex. Support for free-threaded
wheels on Pypi is implemented as well within the 2.1 series only. Initial
pull request and test suite courtesy Lysandros Nikolaou.References: #12881
sql
-
[sql] [bug] Improved the implementation of
UpdateBase.returning()
to use more
robust logic in setting up the.c
collection of a derived statement
such as a CTE. This fixes issues related to RETURNING clauses that feature
expressions based on returned columns with or without qualifying labels.References: #12271
schema
-
[schema] [bug] Fixed issue where
_schema.MetaData.reflect()
did not forward
dialect-specific keyword arguments to the_engine.Inspector
methods, causing options likeoracle_resolve_synonyms
to be ignored
during reflection. The method now ensures that all extra kwargs passed to
_schema.MetaData.reflect()
are forwarded to
_engine.Inspector.get_table_names()
and related reflection methods.
Pull request courtesy Lukáš Kožušník.References: #12884
typing
-
[typing] [bug] Fixed typing bug where the
Session.execute()
method advertised that
it would return aCursorResult
if given an insert/update/delete
statement. This is not the general case as several flavors of ORM
insert/update do not actually yield aCursorResult
which cannot
be differentiated at the typing overload level, so the method now yields
Result
in all cases. For those cases where
CursorResult
is known to be returned and the.rowcount
attribute is required, please usetyping.cast()
.References: #12813
-
[typing] [bug] Added new decorator
_orm.mapped_as_dataclass()
, which is a function
based form of_orm.registry.mapped_as_dataclass()
; the method form
_orm.registry.mapped_as_dataclass()
does not seem to be correctly
recognized within the scope of PEP 681 in recent mypy versions.References: #12855
asyncio
-
[asyncio] [usecase] Generalize the terminate logic employed by the asyncpg dialect to reuse
it in the aiomysql and asyncmy dialect implementation.References: #12273
postgresql
-
[postgresql] [bug] Fixed issue where selecting an enum array column containing NULL values
would fail to parse properly in the PostgreSQL dialect. The
_split_enum_values()
function now correctly handles NULL entries by
converting them to PythonNone
values.References: #12847
-
[postgresql] [bug] Fixed issue where the
_sql.any_()
and_sql.all_()
aggregation
operators would not correctly coerce the datatype of the compared value, in
those cases where the compared value were not a simple int/str etc., such
as a PythonEnum
or other custom value. This would lead to execution
time errors for these values. This issue is essentially the same as
#6515 which was for the now-legacyARRAY.any()
and
ARRAY.all()
methods.References: #12874
sqlite
-
[sqlite] [bug] Fixed issue where SQLite table reflection would fail for tables using
WITHOUT ROWID
and/orSTRICT
table options when the table contained
generated columns. The regular expression used to parseCREATE TABLE
statements for generated column detection has been updated to properly
handle these SQLite table options that appear after the column definitions.
Pull request courtesy Tip ten Brink.References: #12864
mssql
-
[mssql] [bug] Improved the base implementation of the asyncio cursor such that it
includes the option for the underlying driver's cursor to be actively
closed in those cases where it requiresawait
in order to complete the
close sequence, rather than relying on garbage collection to "close" it,
when a plainResult
is returned that does not useawait
for
any of its methods. The previous approach of relying on gc was fine for
MySQL and SQLite dialects but has caused problems with the aioodbc
implementation on top of SQL Server. The new option is enabled
for those dialects which have an "awaitable"cursor.close()
, which
includes the aioodbc, aiomysql, and asyncmy dialects (aiosqlite is also
modified for 2.1 only).References: #12798
-
[mssql] [bug] Fixed issue where the index reflection for SQL Server would
not correctly return the order of the column inside an index
when the order of the columns in the index did not match the
order of the columns in the table.
Pull request courtesy of Allen Chen.References: #12894
-
[mssql] [bug] [reflection] Fixed issue in the MSSQL dialect's foreign key reflection query where
duplicate rows could be returned when a foreign key column and its
referenced primary key column have the same name, and both the referencing
and referenced tables have indexes with the same name. This resulted in an
"ForeignKeyConstraint with duplicate source column references are not
supported" error when attempting to reflect such tables. The query has been
corrected to exclude indexes on the child table when looking for unique
indexes referenced by foreign keys.References: #12907
misc
-
[bug] [ext] Fixed issue caused by an unwanted functional change while typing
theMutableList
class.
This change also reverts all other functional changes done in
the same change.References: #12802
2.0.43
2.0.43
Released: August 11, 2025
orm
-
[orm] [bug] Fixed issue where using the
post_update
feature would apply incorrect
"pre-fetched" values to the ORM objects after a multi-row UPDATE process
completed. These "pre-fetched" values would come from any column that had
anColumn.onupdate
callable or a version id generator used by
orm.Mapper.version_id_generator
; for a version id generator
that delivered random identifiers like timestamps or UUIDs, this incorrect
data would lead to a DELETE statement against those same rows to fail in
the next step.References: #12748
-
[orm] [bug] Fixed issue where
_orm.mapped_column.use_existing_column
parameter in_orm.mapped_column()
would not work when the
_orm.mapped_column()
is used inside of anAnnotated
type alias in
polymorphic inheritance scenarios. The parameter is now properly recognized
and processed during declarative mapping configuration.References: #12787
-
[orm] [bug] Improved the implementation of the
_orm.selectin_polymorphic()
inheritance loader strategy to properly render the IN expressions using
chunks of 500 records each, in the same manner as that of the
_orm.selectinload()
relationship loader strategy. Previously, the IN
expression would be arbitrarily large, leading to failures on databases
that have limits on the size of IN expressions including Oracle Database.References: #12790
engine
-
[engine] [usecase] Added new parameter
create_engine.skip_autocommit_rollback
which provides for a per-dialect feature of preventing the DBAPI
.rollback()
from being called under any circumstances, if the
connection is detected as being in "autocommit" mode. This improves upon
a critical performance issue identified in MySQL dialects where the network
overhead of the.rollback()
call remains prohibitive even if autocommit
mode is set.References: #12784
postgresql
-
[postgresql] [bug] Fixed regression in PostgreSQL dialect where JSONB subscription syntax
would generate incorrect SQL for JSONB-returning functions, causing syntax
errors. The dialect now properly wraps function calls and expressions in
parentheses when using the[]
subscription syntax, generating
(function_call)[index]
instead offunction_call[index]
to comply
with PostgreSQL syntax requirements.References: #12778
oracle
-
[oracle] [usecase] Extended
_oracle.VECTOR
to support sparse vectors. This update
introduces_oracle.VectorStorageType
to specify sparse or dense
storage and added_oracle.SparseVector
. Pull request courtesy
Suraj Shaw.References: #12711
2.0.42
2.0.42
Released: July 29, 2025
orm
-
[orm] [usecase] Added
dataclass_metadata
argument to all ORM attribute constructors
that accept dataclasses parameters, e.g.mapped_column.dataclass_metadata
,
relationship.dataclass_metadata
, etc.
It's passed to the underlying dataclassmetadata
attribute
of the dataclass field. Pull request courtesy Sigmund Lahn.References: #10674
-
[orm] [bug] Implemented the
_orm.defer()
,_orm.undefer()
and
_orm.load_only()
loader options to work for composite attributes, a
use case that had never been supported previously.References: #12593
-
[orm] [bug] Fixed bug where the ORM would pull in the wrong column into an UPDATE when
a key name inside of theValuesBase.values()
method could be located
from an ORM entity mentioned in the statement, but where that ORM entity
was not the actual table that the statement was inserting or updating. An
extra check for this edge case is added to avoid this problem.References: #12692
engine
- [engine] Improved validation of execution parameters passed to the
_engine.Connection.execute()
and similar methods to
provided a better error when tuples are passed in.
Previously the execution would fail with a difficult to
understand error message.
sql
-
[sql] [usecase] The
_sql.values()
construct gains a new method_sql.Values.cte()
,
which allows creation of a named, explicit-columnsCTE
against an
unnamedVALUES
expression, producing a syntax that allows column-oriented
selection from aVALUES
construct on modern versions of PostgreSQL, SQLite,
and MariaDB.References: #12734
-
[sql] [bug] Fixed issue where
select()
of a free-standing scalar expression that
has a unary operator applied, such as negation, would not apply result
processors to the selected column even though the correct type remains in
place for the unary expression.References: #12681
-
[sql] [bug] Hardening of the compiler's actions for UPDATE statements that access
multiple tables to report more specifically when tables or aliases are
referenced in the SET clause; on cases where the backend does not support
secondary tables in the SET clause, an explicit error is raised, and on the
MySQL or similar backends that support such a SET clause, more specific
checking for not-properly-included tables is performed. Overall the change
is preventing these erroneous forms of UPDATE statements from being
compiled, whereas previously it was relied on the database to raise an
error, which was not always guaranteed to happen, or to be non-ambiguous,
due to cases where the parent table included the same column name as the
secondary table column being updated.References: #12692
postgresql
-
[postgresql] [usecase] Added support for PostgreSQL 14+ JSONB subscripting syntax. When connected
to PostgreSQL 14 or later, JSONB columns now automatically use the native
subscript notationjsonb_col['key']
instead of the arrow operator
jsonb_col -> 'key'
for both read and write operations. This provides
better compatibility with PostgreSQL's native JSONB subscripting feature
while maintaining backward compatibility with older PostgreSQL versions.
JSON columns continue to use the traditional arrow syntax regardless of
PostgreSQL version.References: #10927
-
[postgresql] [usecase] Added
postgresql_ops
key to thedialect_options
entry in reflected
dictionary. This maps names of columns used in the index to respective
operator class, if distinct from the default one for column's data type.
Pull request courtesy Denis Laxalde.References: #8664
-
[postgresql] [bug] [reflection] Fixed regression caused by #10665 where the newly modified
constraint reflection query would fail on older versions of PostgreSQL
such as version 9.6. Pull request courtesy Denis Laxalde.References: #12600
-
[postgresql] [bug] Re-raise catched
CancelledError
in the terminate method of the
asyncpg dialect to avoid possible hangs of the code execution.References: #12728
-
[postgresql] [bug] [reflection] Fixes bug that would mistakenly interpret a domain or enum type
with name starting ininterval
as anINTERVAL
type while
reflecting a table.References: #12744
mysql
-
[mysql] [bug] Fixed yet another regression caused by by the DEFAULT rendering changes in
2.0.40 #12425, similar to #12488, this time where using a
CURRENT_TIMESTAMP function with a fractional seconds portion inside a
textual default value would also fail to be recognized as a
non-parenthesized server default.References: #12648
mssql
-
[mssql] [bug] Reworked SQL Server column reflection to be based on the
sys.columns
table rather thaninformation_schema.columns
view. By correctly using
the SQL Serverobject_id()
function as a lead and joining to related
tables on object_id rather than names, this repairs a variety of issues in
SQL Server reflection, including:- Issue where reflected column comments would not correctly line up with the columns themselves in the case that the table had been ALTERed - Correctly targets tables with awkward names such as names with brackets, when reflecting not just the basic table / columns but also extended information including IDENTITY, computed columns, comments which did not work previously - Correctly targets IDENTITY, computed status from temporary tables which did not work previously
References: #12654
2.0.41
2.0.41
Released: May 14, 2025
platform
-
[platform] [bug] Adjusted the test suite as well as the ORM's method of scanning classes for
annotations to work under current beta releases of Python 3.14 (currently
3.14.0b1) as part of an ongoing effort to support the production release of
this Python release. Further changes to Python's means of working with
annotations is expected in subsequent beta releases for which SQLAlchemy's
test suite will need further adjustments.References: #12405
engine
-
[engine] [bug] The error message that is emitted when a URL cannot be parsed no longer
includes the URL itself within the error message.References: #12579
typing
-
[typing] [bug] Removed
__getattr__()
rule fromsqlalchemy/__init__.py
that
appeared to be trying to correct for a previous typographical error in the
imports. This rule interferes with type checking and is removed.References: #12588
postgresql
-
[postgresql] [usecase] Added support for
postgresql_include
keyword argument to
_schema.UniqueConstraint
and_schema.PrimaryKeyConstraint
.
Pull request courtesy Denis Laxalde.References: #10665
mysql
-
[mysql] [bug] Fixed regression caused by the DEFAULT rendering changes in version 2.0.40
via #12425 where using lowercaseon update
in a MySQL server
default would incorrectly apply parenthesis, leading to errors when MySQL
interpreted the rendered DDL. Pull request courtesy Alexander Ruehe.References: #12488
sqlite
-
[sqlite] [bug] Fixed and added test support for some SQLite SQL functions hardcoded into
the compiler, most notably thelocaltimestamp
function which rendered
with incorrect internal quoting.References: #12566
oracle
-
[oracle] [usecase] Added new datatype
_oracle.VECTOR
and accompanying DDL and DQL
support to fully support this type for Oracle Database. This change
includes the base_oracle.VECTOR
type that adds new type-specific
methodsl2_distance
,cosine_distance
,inner_product
as well as
new parametersoracle_vector
for theIndex
construct,
allowing vector indexes to be configured, andoracle_fetch_approximate
for theSelect.fetch()
clause. Pull request courtesy Suraj Shaw.
misc
- [bug] [installation] Removed the "license classifier" from setup.cfg for SQLAlchemy 2.0, which
eliminates loud deprecation warnings when building the package. SQLAlchemy
2.1 will use a full PEP 639 configuration in pyproject.toml while
SQLAlchemy 2.0 remains usingsetup.cfg
for setup.
2.0.40
2.0.40
Released: March 27, 2025
orm
-
[orm] [bug] Fixed regression which occurred as of 2.0.37 where the checked
ArgumentError
that's raised when an inappropriate type or object
is used inside of aMapped
annotation would raiseTypeError
with "boolean value of this clause is not defined" if the object resolved
into a SQL expression in a boolean context, for programs where future
annotations mode was not enabled. This case is now handled explicitly and
a new error message has also been tailored for this case. In addition, as
there are at least half a dozen distinct error scenarios for intepretation
of theMapped
construct, these scenarios have all been unified
under a new subclass ofArgumentError
called
MappedAnnotationError
, to provide some continuity between these
different scenarios, even though specific messaging remains distinct.References: #12329
-
[orm] [bug] Fixed regression in ORM Annotated Declarative class interpretation caused
bytyping_extension==4.13.0
that introduced a different implementation
forTypeAliasType
while SQLAlchemy assumed that it would be equivalent
to thetyping
version, leading to pep-695 type annotations not
resolving to SQL types as expected.References: #12473
sql
-
[sql] [usecase] Implemented support for the GROUPS frame specification in window functions
by adding_sql.over.groups
option to_sql.over()
andFunctionElement.over()
. Pull request courtesy Kaan Dikmen.References: #12450
-
[sql] [bug] Fixed issue in
CTE
constructs involving multiple DDL
_sql.Insert
statements with multiple VALUES parameter sets where the
bound parameter names generated for these parameter sets would conflict,
generating a compile time error.References: #12363
-
[sql] [bug] Fixed regression caused by #7471 leading to a SQL compilation
issue where name disambiguation for two same-named FROM clauses with table
aliasing in use at the same time would produce invalid SQL in the FROM
clause with two "AS" clauses for the aliased table, due to double aliasing.References: #12451
asyncio
-
[asyncio] [bug] Fixed issue where
AsyncSession.get_transaction()
and
AsyncSession.get_nested_transaction()
would fail with
NotImplementedError
if the "proxy transaction" used by
AsyncSession
were garbage collected and needed regeneration.References: #12471
postgresql
-
[postgresql] [usecase] Added support for specifying a list of columns for
SET NULL
andSET DEFAULT
actions ofON DELETE
clause of foreign key definition on
PostgreSQL. Pull request courtesy Denis Laxalde.References: #11595
-
[postgresql] [usecase] When building a PostgreSQL
ARRAY
literal using
_postgresql.array
with an emptyclauses
argument, the
_postgresql.array.type_
parameter is now significant in that it
will be used to render the resultingARRAY[]
SQL expression with a
cast, such asARRAY[]::INTEGER
. Pull request courtesy Denis Laxalde.References: #12432
mysql
-
[mysql] [bug] Support has been re-added for the MySQL-Connector/Python DBAPI using the
mysql+mysqlconnector://
URL scheme. The DBAPI now works against
modern MySQL versions as well as MariaDB versions (in the latter case it's
required to pass charset/collation explicitly). Note however that
server side cursor support is disabled due to unresolved issues with this
driver.References: #12332
-
[mysql] [bug] Fixed issue in MySQL server default reflection where a default that has
spaces would not be correctly reflected. Additionally, expanded the rules
for when to apply parenthesis to a server default in DDL to suit the
general case of a default string that contains non-word characters such as
spaces or operators and is not a string literal.References: #12425
sqlite
-
[sqlite] [bug] Expanded the rules for when to apply parenthesis to a server default in DDL
to suit the general case of a default string that contains non-word
characters such as spaces or operators and is not a string literal.References: #12425
2.0.39
2.0.39
Released: March 11, 2025
orm
-
[orm] [bug] Fixed bug where using DML returning such as
Insert.returning()
with
an ORM model that has_orm.column_property()
constructs that contain
subqueries would fail with an internal error.References: #12326
-
[orm] [bug] Fixed bug in ORM enabled UPDATE (and theoretically DELETE) where using a
multi-table DML statement would not allow ORM mapped columns from mappers
other than the primary UPDATE mapper to be named in the RETURNING clause;
they would be omitted instead and cause a column not found exception.References: #12328
-
[orm] [bug] Fixed issue where the "is ORM" flag of a
select()
or other ORM
statement would not be propagated to the ORMSession
based on a
multi-part operator expression alone, e.g. such asCls.attr + Cls.attr + Cls.attr
or similar, leading to ORM behaviors not taking place for such
statements.References: #12357
-
[orm] [bug] Fixed issue where using
_orm.aliased()
around aCTE
construct could cause inappropriate "duplicate CTE" errors in cases where
that aliased construct appeared multiple times in a single statement.References: #12364
sql
-
[sql] [bug] Added new parameters
AddConstraint.isolate_from_table
and
DropConstraint.isolate_from_table
, defaulting to True, which
both document and allow to be controllable the long-standing behavior of
these two constructs blocking the given constraint from being included
inline within the "CREATE TABLE" sequence, under the assumption that
separate add/drop directives were to be used.References: #12382
typing
-
[typing] [usecase] Support generic types for compound selects (
_sql.union()
,
_sql.union_all()
,_sql.Select.union()
,
_sql.Select.union_all()
, etc) returning the type of the first select.
Pull request courtesy of Mingyu Park.References: #11922
asyncio
-
[asyncio] [bug] Fixed bug where
_asyncio.AsyncResult.scalar()
,
_asyncio.AsyncResult.scalar_one_or_none()
, and
_asyncio.AsyncResult.scalar_one()
would raise anAttributeError
due to a missing internal attribute. Pull request courtesy Allen Ho.References: #12338
postgresql
-
[postgresql] [bug] Add SQL typing to reflection query used to retrieve a the structure
of IDENTITY columns, adding explicit JSON typing to the query to suit
unusual PostgreSQL driver configurations that don't support JSON natively.References: #11751
-
[postgresql] [bug] Fixed issue affecting PostgreSQL 17.3 and greater where reflection of
domains with "NOT NULL" as part of their definition would include an
invalid constraint entry in the data returned by
_postgresql.PGInspector.get_domains()
corresponding to an additional
"NOT NULL" constraint that isn't a CHECK constraint; the existing
"nullable"
entry in the dictionary already indicates if the domain
includes a "not null" constraint. Note that such domains also cannot be
reflected on PostgreSQL 17.0 through 17.2 due to a bug on the PostgreSQL
side; if encountering errors in reflection of domains which include NOT
NULL, upgrade to PostgreSQL server 17.3 or greater. -
[postgresql] [bug] Fixed issue in PostgreSQL network types
_postgresql.INET
,
_postgresql.CIDR
,_postgresql.MACADDR
,
_postgresql.MACADDR8
where sending string values to compare to
these types would render an explicit CAST to VARCHAR, causing some SQL /
driver combinations to fail. Pull request courtesy Denis Laxalde.References: #12060
-
[postgresql] [bug] Fixed compiler issue in the PostgreSQL dialect where incorrect keywords
would be passed when using "FOR UPDATE OF" inside of a subquery.References: #12417
sqlite
-
[sqlite] [bug] Fixed issue that omitted the comma between multiple SQLite table extension
clauses, currentlyWITH ROWID
andSTRICT
, when both options
Table.sqlite_with_rowid
andTable.sqlite_strict
were configured at their non-default settings at the same time. Pull
request courtesy david-fed.References: #12368
2.0.38
2.0.38
Released: February 6, 2025
engine
-
[engine] [bug] Fixed event-related issue where invoking
Engine.execution_options()
on aEngine
multiple times while making use of event-registering
parameters such asisolation_level
would lead to internal errors
involving event registration.References: #12289
sql
-
[sql] [bug] Reorganized the internals by which the
.c
collection on a
FromClause
gets generated so that it is resilient against the
collection being accessed in concurrent fashion. An example is creating a
Alias
orSubquery
and accessing it as a module level
variable. This impacts the Oracle dialect which uses such module-level
global alias objects but is of general use as well.References: #12302
-
[sql] [bug] Fixed SQL composition bug which impacted caching where using a
None
value inside of anin_()
expression would bypass the usual "expanded
bind parameter" logic used by the IN construct, which allows proper caching
to take place.References: #12314
postgresql
-
[postgresql] [usecase] [asyncio] Added an additional
asyncio.shield()
call within the connection
terminate process of the asyncpg driver, to mitigate an issue where
terminate would be prevented from completing under the anyio concurrency
library.References: #12077
-
[postgresql] [bug] Adjusted the asyncpg connection wrapper so that the
connection.transaction()
call sent to asyncpg sendsNone
for
isolation_level
if not otherwise set in the SQLAlchemy dialect/wrapper,
thereby allowing asyncpg to make use of the server level setting for
isolation_level
in the absense of a client-level setting. Previously,
this behavior of asyncpg was blocked by a hardcodedread_committed
.References: #12159
mariadb
-
[mariadb] [bug] [dml] [mysql] Fixed a bug where the MySQL statement compiler would not properly compile
statements where_mysql.Insert.on_duplicate_key_update()
was passed
values that included ORM-mapped attributes (e.g.
InstrumentedAttribute
objects) as keys. Pull request courtesy of
mingyu.References: #12117
sqlite
-
[sqlite] [bug] [aiosqlite] [asyncio] [pool] Changed default connection pool used by the
aiosqlite
dialect
fromNullPool
toAsyncAdaptedQueuePool
; this change
should have been made when 2.0 was first released as thepysqlite
dialect was similarly changed to useQueuePool
as detailed
inchange_7490
.References: #12285
2.0.37
2.0.37
Released: January 9, 2025
orm
-
[orm] [bug] Fixed issue regarding
Union
types that would be present in the
_orm.registry.type_annotation_map
of a_orm.registry
or declarative base class, where aMapped
element that included
one of the subtypes present in thatUnion
would be matched to that
entry, potentially ignoring other entries that matched exactly. The
correct behavior now takes place such that an entry should only match in
_orm.registry.type_annotation_map
exactly, as aUnion
type
is a self-contained type. For example, an attribute withMapped[float]
would previously match to a_orm.registry.type_annotation_map
entryUnion[float, Decimal]
; this will no longer match and will now
only match to an entry that statesfloat
. Pull request courtesy Frazer
McLean.References: #11370
-
[orm] [bug] Fixed bug in how type unions were handled within
_orm.registry.type_annotation_map
as well as
_orm.Mapped
that made the lookup behavior ofa | b
different
from that ofUnion[a, b]
.References: #11944
-
[orm] [bug] Consistently handle
TypeAliasType
(defined in PEP 695) obtained with
thetype X = int
syntax introduced in python 3.12. Now in all cases one
such alias must be explicitly added to the type map for it to be usable
insideMapped
. This change also revises the approach added in
#11305, now requiring theTypeAliasType
to be added to the
type map. Documentation on how unions and type alias types are handled by
SQLAlchemy has been added in the
orm_declarative_mapped_column_type_map
section of the documentation.References: #11955
-
[orm] [bug] Fixed regression caused by an internal code change in response to recent
Mypy releases that caused the very unusual case of a list of ORM-mapped
attribute expressions passed toColumnOperators.in_()
to no longer
be accepted.References: #12019
-
[orm] [bug] Fixed issues in type handling within the
_orm.registry.type_annotation_map
feature which prevented the
use of unions, using either pep-604 orUnion
syntaxes under future
annotations mode, which contained multiple generic types as elements from
being correctly resolvable.References: #12207
-
[orm] [bug] Fixed issue in event system which prevented an event listener from being
attached and detached from multiple class-like objects, namely the
sessionmaker
orscoped_session
targets that assign to
Session
subclasses.References: #12216
sql
-
[sql] [bug] Fixed issue in "lambda SQL" feature where the tracking of bound parameters
could be corrupted if the same lambda were evaluated across multiple
compile phases, including when using the same lambda across multiple engine
instances or with statement caching disabled.References: #12084
postgresql
-
[postgresql] [usecase] The
_postgresql.Range
type now supports
_postgresql.Range.__contains__()
. Pull request courtesy of Frazer
McLean.References: #12093
-
[postgresql] [bug] Fixes issue in
Dialect.get_multi_indexes()
in the PostgreSQL
dialect, where an error would be thrown when attempting to use alembic with
a vector index from the pgvecto.rs extension.References: #11724
-
[postgresql] [bug] Fixed issue where creating a table with a primary column of
_sql.SmallInteger
and using the asyncpg driver would result in
the type being compiled toSERIAL
rather thanSMALLSERIAL
.References: #12170
-
[postgresql] [bug] Adjusted the asyncpg dialect so that an empty SQL string, which is valid
for PostgreSQL server, may be successfully processed at the dialect level,
such as when usingConnection.exec_driver_sql()
. Pull request
courtesy Andrew Jackson.References: #12220
mysql
-
[mysql] [usecase] [mariadb] Added support for the
LIMIT
clause withDELETE
for the MySQL and
MariaDB dialects, to complement the already present option for
UPDATE
. TheDelete.with_dialect_options()
method of the
delete()
construct accepts parameters formysql_limit
and
mariadb_limit
, allowing users to specify a limit on the number of rows
deleted. Pull request courtesy of Pablo Nicolás Estevez.References: #11764
-
[mysql] [bug] [mariadb] Added logic to ensure that the
mysql_limit
andmariadb_limit
parameters ofUpdate.with_dialect_options()
and
Delete.with_dialect_options()
when compiled to string will only
compile if the parameter is passed as an integer; aValueError
is
raised otherwise.
mariadb
-
[mariadb] [usecase] Added sql types
INET4
andINET6
in the MariaDB dialect. Pull
request courtesy Adam Žurek.References: #10720
sqlite
-
[sqlite] [usecase] Added SQLite table option to enable
STRICT
tables. Pull request
courtesy of Guilherme Crocetti.References: #7398
oracle
-
[oracle] [feature] Added new table option
oracle_tablespace
to specify theTABLESPACE
option when creating a table in Oracle. This allows users to define the
tablespace in which the table should be created. Pull request courtesy of
Miguel Grillo.References: #12016
-
[oracle] [usecase] Use the connection attribute
max_identifier_length
available
in oracledb since version 2.5 when determining the identifier length
in the Oracle dialect.References: #12032
-
[oracle] [bug] Fixed compilation of
TABLE
function when used in aFROM
clause in
Oracle Database dialect.References: #12100
-
[oracle] [bug] Fixed issue in oracledb / cx_oracle dialects where output type handlers for
CLOB
were being routed toNVARCHAR
rather thanVARCHAR
, causing
a double conversion to take place.References: #12150
2.0.36
2.0.36
Released: October 15, 2024
orm
-
[orm] [usecase] Added new parameter
_orm.mapped_column.hash
to ORM constructs
such as_orm.mapped_column()
,_orm.relationship()
, etc.,
which is interpreted for ORM Native Dataclasses in the same way as other
dataclass-specific field parameters.References: #11923
-
[orm] [bug] Fixed bug in ORM bulk update/delete where using RETURNING with bulk
update/delete in combination withpopulate_existing
would fail to
accommodate thepopulate_existing
option.References: #11912
-
[orm] [bug] Continuing from #11912, columns marked with
mapped_column.onupdate
,
mapped_column.server_onupdate
, orComputed
are now
refreshed in ORM instances when running an ORM enabled UPDATE with WHERE
criteria, even if the statement does not use RETURNING or
populate_existing
.References: #11917
-
[orm] [bug] Fixed regression caused by fixes to joined eager loading in #11449
released in 2.0.31, where a particular joinedload case could not be
asserted correctly. We now have an example of that case so the assertion
has been repaired to allow for it.References: #11965
-
[orm] [bug] Improved the error message emitted when trying to map as dataclass a class
while also manually providing the__table__
attribute.
This usage is currently not supported.References: #11973
-
[orm] [bug] Refined the check which the ORM lazy loader uses to detect "this would be
loading by primary key and the primary key is NULL, skip loading" to take
into account the current setting for the
orm.Mapper.allow_partial_pks
parameter. If this parameter is
False
, then a composite PK value that has partial NULL elements should
also be skipped. This can apply to some composite overlapping foreign key
configurations.References: #11995
-
[orm] [bug] Fixed bug in ORM "update with WHERE clause" feature where an explicit
.returning()
would interfere with the "fetch" synchronize strategy due
to an assumption that the ORM mapped class featured the primary key columns
in a specific position within the RETURNING. This has been fixed to use
appropriate ORM column targeting.References: #11997
sql
-
[sql] [usecase] Datatypes that are binary based such as
VARBINARY
will resolve to
LargeBinary
when theTypeEngine.as_generic()
method is
called.References: #11978
-
[sql] [bug] [regression] Fixed regression from 1.4 where some datatypes such as those derived from
TypeDecorator
could not be pickled when they were part of a
larger SQL expression composition due to internal supporting structures
themselves not being pickleable.References: #12002
schema
-
[schema] [bug] Fixed bug where SQL functions passed to
_schema.Column.server_default
would not be rendered with the
particular form of parenthesization now required by newer versions of MySQL
and MariaDB. Pull request courtesy of huuya.References: #11317
postgresql
-
[postgresql] [bug] [reflection] Fixed bug in reflection of table comments where unrelated text would be
returned if an entry in thepg_description
table happened to share the
same oid (objoid) as the table being reflected.References: #11961
-
[postgresql] [bug] The
postgresql.JSON
andpostgresql.JSONB
datatypes will
now render a "bind cast" in all cases for all PostgreSQL backends,
including psycopg2, whereas previously it was only enabled for some
backends. This allows greater accuracy in allowing the database server to
recognize when a string value is to be interpreted as JSON.References: #11994
mysql
-
[mysql] [performance] Improved a query used for the MySQL 8 backend when reflecting foreign keys
to be better optimized. Previously, for a database that had millions of
columns across all tables, the query could be prohibitively slow; the query
has been reworked to take better advantage of existing indexes.References: #11975
2.0.35
2.0.35
Released: September 16, 2024
orm
-
[orm] [bug] [typing] Fixed issue where it was not possible to use
typing.Literal
with
Mapped[]
on Python 3.8 and 3.9. Pull request courtesy Frazer McLean.References: #11820
-
[orm] [bug] Fixed issue in ORM evaluator where two datatypes being evaluated with the
SQL concatenator operator would not be checked for
UnevaluatableError
based on their datatype; this missed the case
of_postgresql.JSONB
values being used in a concatenate operation
which is supported by PostgreSQL as well as how SQLAlchemy renders the SQL
for this operation, but does not work at the Python level. By implementing
UnevaluatableError
for this combination, ORM update statements
will now fall back to "expire" when a concatenated JSON value used in a SET
clause is to be synchronized to a Python object.References: #11849
-
[orm] [bug] An warning is emitted if
_orm.joinedload()
or
_orm.subqueryload()
are used as a top level option against a
statement that is not a SELECT statement, such as with an
insert().returning()
. There are no JOINs in INSERT statements nor is
there a "subquery" that can be repurposed for subquery eager loading, and
for UPDATE/DELETE joinedload does not support these either, so it is never
appropriate for this use to pass silently.References: #11853
-
[orm] [bug] Fixed issue where using loader options such as
_orm.selectinload()
with additional criteria in combination with ORM DML such as
_sql.insert()
with RETURNING would not correctly set up internal
contexts required for caching to work correctly, leading to incorrect
results.References: #11855
mysql
-
[mysql] [bug] Fixed issue in mariadbconnector dialect where query string arguments that
weren't checked integer or boolean arguments would be ignored, such as
string arguments likeunix_socket
, etc. As part of this change, the
argument parsing for particular elements such asclient_flags
,
compress
,local_infile
has been made more consistent across all
MySQL / MariaDB dialect which accept each argument. Pull request courtesy
Tobias Alex-Petersen.References: #11870
sqlite
-
[sqlite] [bug] [regression] The changes made for SQLite CHECK constraint reflection in versions 2.0.33
and 2.0.34 , #11832 and #11677, have now been fully
reverted, as users continued to identify existing use cases that stopped
working after this change. For the moment, because SQLite does not
provide any consistent way of delivering information about CHECK
constraints, SQLAlchemy is limited in what CHECK constraint syntaxes can be
reflected, including that a CHECK constraint must be stated all on a
single, independent line (or inline on a column definition) without
newlines, tabs in the constraint definition or unusual characters in the
constraint name. Overall, reflection for SQLite is tailored towards being
able to reflect CREATE TABLE statements that were originally created by
SQLAlchemy DDL constructs. Long term work on a DDL parser that does not
rely upon regular expressions may eventually improve upon this situation.
A wide range of additional cross-dialect CHECK constraint reflection tests
have been added as it was also a bug that these changes did not trip any
existing tests.References: #11840