]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/log
thirdparty/sqlalchemy/sqlalchemy.git
12 days agoMerge "add create_type to Enum" into main
Michael Bayer [Tue, 23 Sep 2025 14:51:45 +0000 (14:51 +0000)] 
Merge "add create_type to Enum" into main

12 days agoImprove asyncpg exception hierarchy and asyncio hierarchies overall
Mike Bayer [Sat, 20 Sep 2025 20:22:28 +0000 (16:22 -0400)] 
Improve asyncpg exception hierarchy and asyncio hierarchies overall

The "emulated" exception hierarchies for the asyncio
drivers such as asyncpg, aiomysql, aioodbc, etc. have been standardized
on a common base :class:`.EmulatedDBAPIException`, which is now what's
available from the :attr:`.StatementException.orig` attribute on a
SQLAlchemy :class:`.DBAPIException` object.   Within :class:`.EmulatedDBAPIException`
and the subclasses in its hiearchy, the original driver-level exception is
also now avaliable via the :attr:`.EmulatedDBAPIException.orig` attribute,
and is also available from :class:`.DBAPIException` directly using the
:attr:`.DBAPIException.driver_exception` attribute.

Added additional emulated error classes for the subclasses of
``asyncpg.exception.IntegrityError`` including ``RestrictViolationError``,
``NotNullViolationError``, ``ForeignKeyViolationError``,
``UniqueViolationError`` ``CheckViolationError``,
``ExclusionViolationError``.  These exceptions are not directly thrown by
SQLAlchemy's asyncio emulation, however are available from the
newly added :attr:`.DBAPIException.driver_exception` attribute when a
:class:`.IntegrityError` is caught.

Fixes: #8047
Change-Id: I6a34e85b055265c087b0615f7c573be8582b3486

2 weeks agoadd create_type to Enum
Mike Bayer [Sun, 21 Sep 2025 16:13:21 +0000 (12:13 -0400)] 
add create_type to Enum

Added new parameter :paramref:`.Enum.create_type` to the Core
:class:`.Enum` class. This parameter is automatically passed to the
corresponding :class:`_postgresql.ENUM` native type during DDL operations,
allowing control over whether the PostgreSQL ENUM type is implicitly
created or dropped within DDL operations that are otherwise targeting
tables only. This provides control over the
:paramref:`_postgresql.ENUM.create_type` behavior without requiring
explicit creation of a :class:`_postgresql.ENUM` object.

Fixes: #10604
Change-Id: I450003ec2a2a65c119fe7ca8ff201392ce6b91e1

2 weeks agoMerge "Apply nested for joined eager m2o w/ GROUP BY, DISTINCT" into main
Michael Bayer [Sun, 21 Sep 2025 16:14:46 +0000 (16:14 +0000)] 
Merge "Apply nested for joined eager m2o w/ GROUP BY, DISTINCT" into main

2 weeks agoApply nested for joined eager m2o w/ GROUP BY, DISTINCT
Mike Bayer [Sun, 21 Sep 2025 14:59:51 +0000 (10:59 -0400)] 
Apply nested for joined eager m2o w/ GROUP BY, DISTINCT

Fixed issue where joined eager loading would fail to use the "nested" form
of the query when GROUP BY or DISTINCT were present if the eager joins
being added were many-to-ones, leading to additional columns in the columns
clause which would then cause errors.  The check for "nested" is tuned to
be enabled for these queries even for many-to-one joined eager loaders, and
the "only do nested if it's one to many" aspect is now localized to when
the query only has LIMIT or OFFSET added.

Fixes: #11226
Change-Id: I0b4b71cacfe1c6a25d0924e0954ceced1e399ca1

2 weeks agoremove _py3k suffixes from test files
Mike Bayer [Sat, 20 Sep 2025 22:31:25 +0000 (18:31 -0400)] 
remove _py3k suffixes from test files

on the theme of 2.0/2.1 are relatively similar right now, do
some more cleanup removing the py3k suffixes that we dont need anymore.

I'm not sure that the logic that would search for these suffixes is
even present anymore and I would guess we removed it when we removed
py2k support.  However, I am planning on possibly bringing it back
for some of the py314 stuff, so I still want to be able to do
suffix stuff.  that will be for another patch.

Change-Id: I929e6edd922f8d5f943acce77191fb1e3035b42c

2 weeks agoMerge "deprecate ARRAY.any(), ARRAY.all(), postgresql.Any(), postgresql.All()" into...
Michael Bayer [Sat, 20 Sep 2025 21:29:29 +0000 (21:29 +0000)] 
Merge "deprecate ARRAY.any(), ARRAY.all(), postgresql.Any(), postgresql.All()" into main

2 weeks agodeprecate ARRAY.any(), ARRAY.all(), postgresql.Any(), postgresql.All()
Mike Bayer [Sat, 20 Sep 2025 16:22:48 +0000 (12:22 -0400)] 
deprecate ARRAY.any(), ARRAY.all(), postgresql.Any(), postgresql.All()

The :meth:`_types.ARRAY.Comparator.any` and
:meth:`_types.ARRAY.Comparator.all` methods for the :class:`_types.ARRAY`
type are now deprecated for removal; these two methods along with
:func:`_postgresql.Any` and :func:`_postgresql.All` have been legacy for
some time as they are superseded by the :func:`_sql.any_` and
:func:`_sql.all_` functions, which feature more intutive use.

Fixes: #10821
Change-Id: I8eb3bbcb98af4ee60a21767dc3bdac771cbc0b4c

2 weeks agoMerge "Use ARRAY type for any_(), all_() coercion" into main
Michael Bayer [Sat, 20 Sep 2025 20:34:07 +0000 (20:34 +0000)] 
Merge "Use ARRAY type for any_(), all_() coercion" into main

2 weeks agoUse ARRAY type for any_(), all_() coercion
Mike Bayer [Sat, 20 Sep 2025 18:08:55 +0000 (14:08 -0400)] 
Use ARRAY type for any_(), all_() coercion

Fixed issue where the :func:`_sql.any_` and :func:`_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 Python ``Enum`` or other custom value.   This would lead to execution
time errors for these values.  This issue is essentially the same as
:ticket:`6515` which was for the now-legacy :meth:`.ARRAY.any` and
:meth:`.ARRAY.all` methods.

Fixes: #12874
Change-Id: I980894c23b9974bc84d584a1a4c5fae72dded6d3

2 weeks agoMerge "refactor test_sqlite into a package" into main
Michael Bayer [Sat, 20 Sep 2025 18:12:11 +0000 (18:12 +0000)] 
Merge "refactor test_sqlite into a package" into main

2 weeks agoMerge "raise for ENUM/DOMAIN with reserved type name and no schema" into main
Michael Bayer [Sat, 20 Sep 2025 18:11:57 +0000 (18:11 +0000)] 
Merge "raise for ENUM/DOMAIN with reserved type name and no schema" into main

2 weeks agoraise for ENUM/DOMAIN with reserved type name and no schema
KapilDagur [Sat, 13 Sep 2025 18:37:31 +0000 (14:37 -0400)] 
raise for ENUM/DOMAIN with reserved type name and no schema

A :class:`.CompileError` is raised if attempting to create a PostgreSQL
:class:`_postgresql.ENUM` or :class:`_postgresql.DOMAIN` datatype using a
name that matches a known pg_catalog datatype name, and a default schema is
not specified.   These types must be explicit within a schema in order to
be differentiated from the built-in pg_catalog type.  The "public" or
otherwise default schema is not chosen by default here since the type can
only be reflected back using the explicit schema name as well (it is
otherwise not visible due to the pg_catalog name).  Pull request courtesy
Kapil Dagur.

We originally thought we were going to do some default logic for the
default / "public" schema however this produces a type that is not
symmetric to its reflection, since the schema name must be explicit
for our current reflection queries.

So since it's an extremely bad idea to make an ENUM/DOMAIN with a
reserved type name anyway, we raise a compileerror if the type
has a known name.   this is not robust against other names that
might exist in pg_catalog or other schemas that are in the search
path with these names.  People just have to know what they're doing
here, the error here only covers a small subset of real world cases.

Fixes: #12761
Closes: #12822
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12822
Pull-request-sha: 793cf27be28a37e8882d89ba6b79570c79f936ac

Change-Id: I9df9c216ab4102f06685a64ae7e55db1b3a9535e

2 weeks agorefactor test_sqlite into a package
Mike Bayer [Sat, 20 Sep 2025 15:27:12 +0000 (11:27 -0400)] 
refactor test_sqlite into a package

this is many years overdue, let's do it while 2.1/2.0 are in
sync and we are far away from 1.4 now

Change-Id: Icf90f957e4d56382a4c91250f55bec4c7abc9d79

2 weeks agolimit STRICT to appropraite sqlite versions
Mike Bayer [Fri, 19 Sep 2025 20:35:44 +0000 (16:35 -0400)] 
limit STRICT to appropraite sqlite versions

Change-Id: Id7c302e9a182b0aa2cddd255d44afc3aa7bb77f4

2 weeks agofix tests for aggregate_order_by
Mike Bayer [Fri, 19 Sep 2025 19:18:39 +0000 (15:18 -0400)] 
fix tests for aggregate_order_by

forgot this doesnt work on sqlite older than 3.44

Change-Id: Icebc2ffaceb078a436a8f61ba583bc05b77f680d

2 weeks agoMerge "Add note regarding indexes with subscription of jsonb" into main
Michael Bayer [Fri, 19 Sep 2025 18:58:51 +0000 (18:58 +0000)] 
Merge "Add note regarding indexes with subscription of jsonb" into main

2 weeks agoAdd note regarding indexes with subscription of jsonb
Federico Caselli [Wed, 17 Sep 2025 17:12:39 +0000 (19:12 +0200)] 
Add note regarding indexes with subscription of jsonb

Fixes: #12868
Change-Id: I2a5a6a94a7a8f8796d898d4b7e69967a981c59e8

2 weeks agoadd RegistryEvents
Mike Bayer [Sun, 31 Aug 2025 22:53:01 +0000 (18:53 -0400)] 
add RegistryEvents

Added :class:`_orm.RegistryEvents` event class that allows event listeners
to be established on a :class:`_orm.registry` object. The new class
provides three events: :meth:`_orm.RegistryEvents.resolve_type_annotation`
which allows customization of type annotation resolution that can
supplement or replace the use of the
:paramref:`.registry.type_annotation_map` dictionary, including that it can
be helpful with custom resolution for complex types such as those of
:pep:`695`, as well as :meth:`_orm.RegistryEvents.before_configured` and
:meth:`_orm.RegistryEvents.after_configured`, which are registry-local
forms of the mapper-wide version of these hooks.

note this change was prematurely merged in 7111dc0cbaae and reverted
for re-review and additional changes.

Fixes: #9832
(cherry picked from commit 7111dc0cbaae2070173e9f4a054745ee7d036dfa)
Change-Id: I8d69f5c7e0d004f98b7449fefe87a03bb0f29e39

2 weeks agoMerge "Add FunctionElement.aggregate_order_by" into main
Michael Bayer [Fri, 19 Sep 2025 16:37:55 +0000 (16:37 +0000)] 
Merge "Add FunctionElement.aggregate_order_by" into main

2 weeks agoclarify clauses argument for order_by, group_by
Mike Bayer [Fri, 19 Sep 2025 14:32:43 +0000 (10:32 -0400)] 
clarify clauses argument for order_by, group_by

Change-Id: Idabfde4a6850a2649a2f32dc42d0320f1ec7692d

2 weeks agoAdd FunctionElement.aggregate_order_by
Reuven Starodubski [Thu, 11 Sep 2025 17:33:59 +0000 (13:33 -0400)] 
Add FunctionElement.aggregate_order_by

Added new generalized aggregate function ordering to functions via the
:func:`_functions.FunctionElement.aggregate_order_by` method, which
receives an expression and generates the appropriate embedded "ORDER BY" or
"WITHIN GROUP (ORDER BY)" phrase depending on backend database.  This new
function supersedes the use of the PostgreSQL
:func:`_postgresql.aggregate_order_by` function, which remains present for
backward compatibility.   To complement the new parameter, the
:paramref:`_functions.aggregate_strings.order_by` which adds ORDER BY
capability to the :class:`_functions.aggregate_strings` dialect-agnostic
function which works for all included backends. Thanks much to Reuven
Starodubski with help on this patch.

Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Fixes: #12853
Closes: #12856
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12856
Pull-request-sha: d93fb591751227eb1f96052ea3ad449f511f70b3

Change-Id: I8eb41ff2d57695963a358b5f0017ca9372f15f70

2 weeks agounmapped_dataclass
Mike Bayer [Mon, 14 Jul 2025 17:50:09 +0000 (13:50 -0400)] 
unmapped_dataclass

Reworked the handling of classes which extend from MappedAsDataclass but
are not themselves mapped, i.e. the declarative base as well as any
mixins or abstract classes.  These classes as before are turned into
real dataclasses, however a scan now takes place across the mapped
elements such as mapped_column(), relationship(), etc. so that we may
also take into account dataclasses.field-specific parameters like
init=False, repr, etc.  The main use case for this is so that mixin
dataclasses may make use of "default" in fields while not being rejected
by the dataclasses constructor.  The generated classes are more
functional as dataclasses in a standalone fashion as well, even though
this is not their intended use.  As a standalone dataclass, the one
feature that does not work is a field that has
a default with init=False, because we still need to have a
mapped_column() or similar present at the class level for the class
to work as a superclass.

The change also addes the :func:`_orm.unmapped_dataclass` decorator
function, which may be used
to create unmapped superclasses in a mapped hierarchy that is using the
:func:`_orm.mapped_dataclass` decorator to create mapped dataclasses.
Previously there was no way to use unmapped dataclass mixins with
the decorator approach.

Finally, the warning added in 2.0 for :ticket:`9350` is turned into
an error as mentioned for 2.1, since we're deep into dataclass hierarchy
changes here.

Fixes: #12854
Change-Id: I11cd8c628d49e9ff1bdbda8a09f4112b40d84be7

2 weeks agoMerge "Fix get_columns sqlite reflection rejecting tables with WITHOUT_ROWID and...
Michael Bayer [Mon, 15 Sep 2025 21:55:45 +0000 (21:55 +0000)] 
Merge "Fix get_columns sqlite reflection rejecting tables with WITHOUT_ROWID and/or STRICT for generated column case" into main

2 weeks agoRevert "add RegistryEvents"
Mike Bayer [Mon, 15 Sep 2025 21:26:29 +0000 (17:26 -0400)] 
Revert "add RegistryEvents"

This reverts commit 7111dc0cbaae2070173e9f4a054745ee7d036dfa.

Review had 18 comments still open

2 weeks agoFix get_columns sqlite reflection rejecting tables with WITHOUT_ROWID and/or STRICT...
Tip ten Brink [Mon, 15 Sep 2025 12:58:40 +0000 (08:58 -0400)] 
Fix get_columns sqlite reflection rejecting tables with WITHOUT_ROWID and/or STRICT for generated column case

Fixed issue where SQLite table reflection would fail for tables using
``WITHOUT ROWID`` and/or ``STRICT`` table options when the table contained
generated columns. The regular expression used to parse ``CREATE 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.

Fixes: #12864
Closes: #12865
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12865
Pull-request-sha: 833420afc72f1918a9ca315209ce6664a18ba07f

Change-Id: Ia25c05746055a66234531b4f1275bd3a2f3b44ad

2 weeks agoMerge "add RegistryEvents" into main
Michael Bayer [Mon, 15 Sep 2025 13:42:17 +0000 (13:42 +0000)] 
Merge "add RegistryEvents" into main

3 weeks agoremove confusing "with_parent()" from query-enabled properties example
Mike Bayer [Sat, 13 Sep 2025 13:54:38 +0000 (09:54 -0400)] 
remove confusing "with_parent()" from query-enabled properties example

references: #12862
Change-Id: I22ee9fa0c566458a465867e307a77c2eb0ddcdd0

3 weeks agodo the mypy dance
Mike Bayer [Fri, 12 Sep 2025 23:01:31 +0000 (19:01 -0400)] 
do the mypy dance

version 1.18.1.  lots of i have no idea situations.
just add ignores, seems pretty pointless

Change-Id: Ieb1466df3f45fa6b8d11ccd36c7164645740ba35

3 weeks agoAdd function mapped_as_dataclass
Mike Bayer [Tue, 9 Sep 2025 19:16:45 +0000 (15:16 -0400)] 
Add function mapped_as_dataclass

Added new decorator :func:`_orm.mapped_as_dataclass`, which is a function
based form of :meth:`_orm.registry.mapped_as_dataclass`; the method form
:meth:`_orm.registry.mapped_as_dataclass` does not seem to be correctly
recognized within the scope of :pep:`681` in recent mypy versions.

The new function is tested and mentioned in the docs, in 2.1 in a
subsequent patch (probably the one that adds unmapped_dataclass also)
we'll switch this new decorator to be the prominent one.

also alphabetize mapping_api.rst.  while the summary box at the top
auto-sorts, have the sidebar alpha also, it's kind of weird how
these were in no order at all

Fixes: #12855
Change-Id: If98724fd466004ec4c8a312a0cbf1c934a6ce9e3

3 weeks agoadd RegistryEvents
Mike Bayer [Sun, 31 Aug 2025 22:53:01 +0000 (18:53 -0400)] 
add RegistryEvents

Added :class:`_orm.RegistryEvents` event class that allows event listeners
to be established on a :class:`_orm.registry` object. The new class
provides three events: :meth:`_orm.RegistryEvents.resolve_type_annotation`
which allows customization of type annotation resolution that can
supplement or replace the use of the
:paramref:`.registry.type_annotation_map` dictionary, including that it can
be helpful with custom resolution for complex types such as those of
:pep:`695`, as well as :meth:`_orm.RegistryEvents.before_configured` and
:meth:`_orm.RegistryEvents.after_configured`, which are registry-local
forms of the mapper-wide version of these hooks.

Fixes: #9832
Change-Id: I32b55de8625ec435edf916a91e65f61fda50cd51

4 weeks agodoc updates, localize test fixtures
Mike Bayer [Sun, 7 Sep 2025 00:20:00 +0000 (20:20 -0400)] 
doc updates, localize test fixtures

testing with types is inherently awkward and subject
to changes in python interpreters (such as all the recent python 3.14
stuff we had them fix), but in this suite we already have a lot of
types that are defined inline inside of test methods.   so since that's
how many of the tests work anyway, organize the big series of pep-695
and pep-593 structures into fixtures or individual tests to make
the whole suite easier to follow.   pyright complains quite a lot
about this, so if this becomes a bigger issue for say mypy /pep484
target, we may have to revisit (which I'd likely do with more ignores)
or if function/method-local type declarations with global becomes a runtime
issue in py3.15 or something, we can revisit then where we would in
theory need to convert the entire suite, which I'd do with a more
consistent naming style for everything.

but for now try to go with fixtures / local type declarations so that
we dont have to wonder where all these types are used.

Change-Id: Ibe8f447eaa10f5e927b1122c8b608f11a5f5bc97

4 weeks agoMerge "liberalize pep695 matching" into main
Michael Bayer [Sat, 6 Sep 2025 22:58:23 +0000 (22:58 +0000)] 
Merge "liberalize pep695 matching" into main

4 weeks agoliberalize pep695 matching
Mike Bayer [Thu, 4 Sep 2025 01:44:33 +0000 (21:44 -0400)] 
liberalize pep695 matching

after many days of discussion we are moving to liberalize the
matching rules used for pep695 to the simple rule that we will resolve
a pep695 type to its immediate ``__value__`` without requiring that
it be present in the type map, however without any further recursive
checks (that is, we will not resolve ``__value__`` of ``__value__``).
This allows the vast majority of simple uses of pep695 types to not
require entries in the type map, including when the type points
to a simple Python type or any type that is present in the type_map.
Also supported is resolution of generic pep695 types against the
right side, including for Annotated types.

The change here in 2.1 will form the base for a revised approach
to the RegistryEvents patch for #9832, which will still provide
the RegistryEvents.resolve_type_annotation hook.   In 2.0, we need
to scale back the warnings that are emitted so portions of this patch
will also be backported including similar changes to the test suite.

Fixes: #12829
Change-Id: Ib6e379793335da3f33f6ca2cd6874a6eaf1e36f4

4 weeks agointerpret NULL in PG enum array values
Mike Bayer [Fri, 5 Sep 2025 13:29:34 +0000 (09:29 -0400)] 
interpret NULL in PG enum array values

Fixed issue where selecting an enum array column containing NULL values
would fail to parse properly in the PostgreSQL dialect. The
:func:`._split_enum_values` function now correctly handles NULL entries by
converting them to Python ``None`` values.

Fixes: #12847
Change-Id: I39d10bc1be6b458da7e5d3f4b740f8faafd0adc5

4 weeks agoremove upfront sanitization of entities from joins
Mike Bayer [Tue, 2 Sep 2025 16:26:06 +0000 (12:26 -0400)] 
remove upfront sanitization of entities from joins

ORM entities can now be involved within the SQL expressions used within
:paramref:`_orm.relationship.primaryjoin` and
:paramref:`_orm.relationship.secondaryjoin` parameters without the ORM
entity information being implicitly sanitized, allowing ORM-specific
features such as single-inheritance criteria in subqueries to continue
working even when used in this context.   This is made possible by overall
ORM simplifications that occurred as of the 2.0 series.  The changes here
also provide a performance boost (up to 20%) for certain query compilation
scenarios.

Here we see that we're not only able to remove the
relationships deannotation steps, but we can also change
context -> _get_current_adapter() to be an unconditional
adapter, since the only remaining case where it was conditional
was the polymorphic_adapter.  that adapter is itself
only used for exotic joined inh cases against select
statements (totally not used by anyone) or by abstract
concrete setups.   That lets us remove a whole host
of orm_annotate stuff that doesn't apply anymore.

if this does lead to user regressions in 2.1 it will be
a good reason for us to revisit the complexity here in
any case.

Fixes: #12843
Change-Id: Ic1c6e72d70ec6a27b73495c1a56e9307c9280133

4 weeks agomove callcount tests to py313, 314
Mike Bayer [Tue, 2 Sep 2025 21:11:31 +0000 (17:11 -0400)] 
move callcount tests to py313, 314

Some other gerrits are making changes to callcounts
so modernize these first

Change-Id: If2125883e36146bfdae8b2e29c0db537985750ac

4 weeks agosupport omission of standard event listen example
Mike Bayer [Tue, 2 Sep 2025 15:10:51 +0000 (11:10 -0400)] 
support omission of standard event listen example

The required targets for before_configured() and after_configured()
are the Mapper (and soon to include registry things as well in 2.1),
update the automatic doc example thing to be able to be skipped
when there are special instructions for the target.

Also updates the event docs a bit, which were very old and
written in more of that "disorganized wall of details" style
that was very hard to unlearn

Change-Id: I729d08e25b721f4c993aa1856038b27643fc95d0

5 weeks agoMerge "warn on failed aliased" into main
Michael Bayer [Sun, 31 Aug 2025 21:10:53 +0000 (21:10 +0000)] 
Merge "warn on failed aliased" into main

5 weeks agowarn on failed aliased
Mike Bayer [Fri, 8 Aug 2025 16:17:16 +0000 (12:17 -0400)] 
warn on failed aliased

The :func:`_orm.aliased` object now emits warnings when an attribute is
accessed on an aliased class that cannot be located in the target
selectable, for those cases where the :func:`_orm.aliased` is against a
different FROM clause than the regular mapped table (such as a subquery).
This helps users identify cases where column names don't match between the
aliased class and the underlying selectable. When
:paramref:`_orm.aliased.adapt_on_names` is ``True``, the warning suggests
checking the column name; when ``False``, it suggests using the
``adapt_on_names`` parameter for name-based matching.

Fixes: #12838
Change-Id: I4294b57f24dd3fd7741e0bcbd9b521c841ace903

5 weeks agoMerge "add session-wide execution_options" into main
Michael Bayer [Sun, 31 Aug 2025 14:42:30 +0000 (14:42 +0000)] 
Merge "add session-wide execution_options" into main

5 weeks agoMerge "add OperatorClasses to gate mismatched operator use" into main
Michael Bayer [Sun, 31 Aug 2025 14:18:56 +0000 (14:18 +0000)] 
Merge "add OperatorClasses to gate mismatched operator use" into main

5 weeks agoadd session-wide execution_options
Mike Bayer [Tue, 26 Aug 2025 20:54:39 +0000 (16:54 -0400)] 
add session-wide execution_options

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

Fixes: #12659
Change-Id: I6e19e1567e0c04df32ba1d43baf420fb762f155c

5 weeks agoMerge "use fixture_session() fixture, remove "future" terminology" into main
Michael Bayer [Wed, 27 Aug 2025 00:31:55 +0000 (00:31 +0000)] 
Merge "use fixture_session() fixture, remove "future" terminology" into main

5 weeks agoMerge "use _generate_columns_plus_names for ddl returning c populate" into main
Michael Bayer [Wed, 27 Aug 2025 00:14:57 +0000 (00:14 +0000)] 
Merge "use _generate_columns_plus_names for ddl returning c populate" into main

5 weeks agouse fixture_session() fixture, remove "future" terminology
Mike Bayer [Tue, 26 Aug 2025 23:14:20 +0000 (19:14 -0400)] 
use fixture_session() fixture, remove "future" terminology

Tests here are sporadically failing on aiosqlite and it
seems the use of Session() rather than fixture_session() may be
causing connections to be cleaned up in GC, leading to table
exists race conditions.

Remove the concept of "future" since everything is "future" now

Change-Id: Ibf9ec8c47d3ab4ce95566811c9f6729ddd78a7d3

5 weeks agoMerge "Create terminate mixin" into main
Michael Bayer [Tue, 26 Aug 2025 22:21:07 +0000 (22:21 +0000)] 
Merge "Create terminate mixin" into main

5 weeks agouse _generate_columns_plus_names for ddl returning c populate
Mike Bayer [Tue, 26 Aug 2025 18:47:34 +0000 (14:47 -0400)] 
use _generate_columns_plus_names for ddl returning c populate

Improved the implementation of :meth:`.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.

Co-authored-by: Juhyeong Ko <dury.ko@gmail.com>
Fixes: #12271
Change-Id: Id0d486d4304002f1affdec2e7662ac2965936f2a

5 weeks agosupport configurable None behavior for composites
Mike Bayer [Mon, 5 May 2025 12:36:05 +0000 (08:36 -0400)] 
support configurable None behavior for composites

Added new parameter :paramref:`_orm.composite.return_none_on` to
:func:`_orm.composite`, which allows control over if and when this
composite attribute should resolve to ``None`` when queried or retrieved
from the object directly.  By default, a composite object is always present
on the attribute, including for a pending object which is a behavioral
change since 2.0.   When :paramref:`_orm.composite.return_none_on` is
specified, a callable is passed that returns True or False to indicate if
the given arguments indicate the composite should be returned as None. This
parameter may also be set automatically when ORM Annotated Declarative is
used; if the annotation is given as ``Mapped[SomeClass|None]``, a
:paramref:`_orm.composite.return_none_on` rule is applied that will return
``None`` if all contained columns are themselves ``None``.

Fixes: #12570
Change-Id: Iab01ac46065689da1332c9f80dedbc7eb0f5380b

5 weeks agoadd OperatorClasses to gate mismatched operator use
Mike Bayer [Wed, 16 Jul 2025 16:14:27 +0000 (12:14 -0400)] 
add OperatorClasses to gate mismatched operator use

Added a new concept of "operator classes" to the SQL operators supported by
SQLAlchemy, represented within the enum :class:`.OperatorClass`.  The
purpose of this structure is to provide an extra layer of validation when a
particular kind of SQL operation is used with a particular datatype, to
catch early the use of an operator that does not have any relevance to the
datatype in use; a simple example is an integer or numeric column used with
a "string match" operator.

Fixes: #12736
Change-Id: I44f46d7326aef6847dbf0cf7a325833f8e347da6

5 weeks agoMerge "more extensibility for asc/desc" into main
Michael Bayer [Mon, 25 Aug 2025 15:37:24 +0000 (15:37 +0000)] 
Merge "more extensibility for asc/desc" into main

5 weeks agoMerge "ensure datatype roundtrips for JSON dialects" into main
Michael Bayer [Mon, 25 Aug 2025 15:36:54 +0000 (15:36 +0000)] 
Merge "ensure datatype roundtrips for JSON dialects" into main

5 weeks agoensure datatype roundtrips for JSON dialects
Mike Bayer [Fri, 22 Aug 2025 22:12:13 +0000 (18:12 -0400)] 
ensure datatype roundtrips for JSON dialects

Improved the behavior of JSON accessors :meth:`.JSON.Comparator.as_string`,
:meth:`.JSON.Comparator.as_boolean`, :meth:`.JSON.Comparator.as_float`,
:meth:`.JSON.Comparator.as_integer` to use CAST in a similar way that
the PostgreSQL, MySQL and SQL Server dialects do to help enforce the
expected Python type is returned.

The :meth:`.JSON.Comparator.as_boolean` method when used on a JSON value on
SQL Server will now force a cast to occur for values that are not simple
`true`/`false` JSON literals, forcing SQL Server to attempt to interpret
the given value as a 1/0 BIT, or raise an error if not possible. Previously
the expression would return NULL.

Fixes: #11074
Change-Id: I5024b78ec2fa6b61a9c6ee176112f1b761eeab98

5 weeks agoMerge "remove python 3.9 support since it's close to eol" into main
Michael Bayer [Mon, 25 Aug 2025 13:50:43 +0000 (13:50 +0000)] 
Merge "remove python 3.9 support since it's close to eol" into main

6 weeks agoremove python 3.9 support since it's close to eol
Federico Caselli [Thu, 21 Aug 2025 20:53:15 +0000 (22:53 +0200)] 
remove python 3.9 support since it's close to eol

Fixes: #12819
Change-Id: I60f848226c1fef2a769845938d6afa3d3c5d0509

6 weeks agomore extensibility for asc/desc
Mike Bayer [Tue, 29 Jul 2025 18:19:34 +0000 (14:19 -0400)] 
more extensibility for asc/desc

Improved the behavior of standalone "operators" like :func:`_sql.desc`,
:func:`_sql.asc`, :func:`_sql.all_`, etc. so that they consult the given
expression object for an overriding method for that operator, even if the
object is not itself a ``ClauseElement``, such as if it's an ORM attribute.
This allows custom comparators for things like :func:`_orm.composite` to
provide custom implementations of methods like ``desc()``, ``asc()``, etc.

Added default implementations of :meth:`.ColumnOperators.desc`,
:meth:`.ColumnOperators.asc`, :meth:`.ColumnOperators.nulls_first`,
:meth:`.ColumnOperators.nulls_last` to :func:`_orm.composite` attributes,
by default applying the modifier to all contained columns.  Can be
overridden using a custom comparator.

Fixes: #12769
Change-Id: I055ce79bf7ac31fb61d48bc3ab34799d42fb6336

6 weeks agoMerge "ensure assoc proxy from aliased() is generated in correct context" into main
Michael Bayer [Fri, 22 Aug 2025 17:07:13 +0000 (17:07 +0000)] 
Merge "ensure assoc proxy from aliased() is generated in correct context" into main

6 weeks agoensure assoc proxy from aliased() is generated in correct context
Mike Bayer [Thu, 21 Aug 2025 15:20:11 +0000 (11:20 -0400)] 
ensure assoc proxy from aliased() is generated in correct context

Improved association proxy to behave slightly better when the parent class
is used in an :func:`_orm.aliased` construct, so that the proxy as
delivered by the :class:`.Aliased` behaves appropriate in terms of that
aliased construct, including operators like ``.any()`` and ``.has()`` work
correctly.

Fixes: #11622
Change-Id: I6220d984d4323a01a38bd89cfbb1bae46d81c24e

6 weeks agoAdd arm64 wheel builds and tests (#12816)
Finn Womack [Thu, 21 Aug 2025 19:54:28 +0000 (12:54 -0700)] 
Add arm64 wheel builds and tests (#12816)

* add windows-11-arm tests

* add windows-11-arm builds

* add workflow fork trigger

* add fork branch push trigger

* remove fork trigger

* remove fork trigger

* Add comment

6 weeks agoFix typing for `hybrid_property.__set__` to properly validate setter values
Micah Denbraver [Wed, 20 Aug 2025 20:58:02 +0000 (16:58 -0400)] 
Fix typing for `hybrid_property.__set__` to properly validate setter values

While iterating on some typing improvements, my colleague @seamuswn pointed out mypy wasn't catching when values with invalid types were set using a `hybrid_property` setter. I believe this is all that's needed to fix the typing.

### Description
Adjust `hybrid_property.__set__` to expect a value of the type that matches the generic's type variable.

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [x] A documentation / typographical / small typing error fix
- Good to go, no issue or tests are needed
- [ ] A short code fix
- please include the issue number, and create an issue if none exists, which
  must include a complete example of the issue.  one line code fixes without an
  issue and demonstration will not be accepted.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
- please include the issue number, and create an issue if none exists, which must
  include a complete example of how the feature would look.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests.

**Have a nice day!**

Closes: #12814
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12814
Pull-request-sha: 8a17b26aea264acf70c52de324b8ccb92b469f2d

Change-Id: Ic99ccc68a32354ef6fe013ec17242058ad2d6d63

6 weeks agoMerge "restore functionality in list" into main
Federico Caselli [Tue, 19 Aug 2025 17:26:25 +0000 (17:26 +0000)] 
Merge "restore functionality in list" into main

6 weeks agoCreate terminate mixin
Federico Caselli [Thu, 23 Jan 2025 21:42:14 +0000 (22:42 +0100)] 
Create terminate mixin

Generalize the terminate logic employed by the asyncpg dialect to reuse
it in the aiomysql and asyncmy dialect implementation.

Fixes: #12273
Change-Id: Iddb658b7118de774f169e31e888a8aae1c7c6ec2

6 weeks agorestore functionality in list
Federico Caselli [Thu, 14 Aug 2025 22:05:07 +0000 (00:05 +0200)] 
restore functionality in list

Fixed issue caused by an unwanted functional change while typing
the :class:`.MutableList` class.
This change also reverts all other functional changes done in
the same change, commit ba0e508141206efc55cdab91df21c18e7dd63c80

Fixes: #12802
Change-Id: I007aa86aec881241ea42ce59d1b078cf8c6829bb

6 weeks agoWe can't promise CursorResult from session.execute()
Mike Bayer [Mon, 18 Aug 2025 15:01:47 +0000 (11:01 -0400)] 
We can't promise CursorResult from session.execute()

Fixed typing bug where the :meth:`.Session.execute` method advertised that
it would return a :class:`.CursorResult` if given an insert/update/delete
statement.  This is not the general case as several flavors of ORM
insert/update do not actually yield a :class:`.CursorResult` which cannot
be differentiated at the typing overload level, so the method now yields
:class:`.Result` in all cases.  For those cases where
:class:`.CursorResult` is known to be returned and the ``.rowcount``
attribute is required, please use ``typing.cast()``.

Fixes: #12813
Change-Id: I8a7197100db312b3898c66ceddd6638e68c6bb44

7 weeks agohttphost string
Mike Bayer [Sat, 16 Aug 2025 13:58:07 +0000 (09:58 -0400)] 
httphost string

Change-Id: I056c3c5e68b41060125d670de35c53fa550c36ca

7 weeks agouse ssh host
Mike Bayer [Sat, 16 Aug 2025 13:41:58 +0000 (09:41 -0400)] 
use ssh host

Change-Id: I7fafc3c8b48c042bf63c31ef697cfa6dad8bca97

7 weeks agoclose aio cursors etc. that require await close
Mike Bayer [Tue, 12 Aug 2025 19:25:15 +0000 (15:25 -0400)] 
close aio cursors etc. that require await close

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 requires ``await`` in order to complete the
close sequence, rather than relying on garbage collection to "close" it,
when a plain :class:`.Result` is returned that does not use ``await`` 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).

Fixes: #12798
Change-Id: Ib17d611201fedf9780dfe3d760760ace99a8835c

7 weeks agocherry-pick changelog update for 2.0.44
Mike Bayer [Mon, 11 Aug 2025 14:25:16 +0000 (10:25 -0400)] 
cherry-pick changelog update for 2.0.44

7 weeks agocherry-pick changelog from 2.0.43
Mike Bayer [Mon, 11 Aug 2025 14:25:16 +0000 (10:25 -0400)] 
cherry-pick changelog from 2.0.43

7 weeks agomaintain alphabetical create_engine() param ordering
Mike Bayer [Mon, 11 Aug 2025 14:19:12 +0000 (10:19 -0400)] 
maintain alphabetical create_engine() param ordering

the name changed on this so it needs to be moved down

Change-Id: I119c3f5db9262c80b6dd2175e1e56073776607cf

7 weeks agodoc fixes
Mike Bayer [Mon, 11 Aug 2025 14:15:12 +0000 (10:15 -0400)] 
doc fixes

Change-Id: Iee65f09ea17bfa7a39fe3da05f22007f92b76f29

7 weeks agoFixes: #12711 Added sparse vector support in Oracle
suraj [Mon, 11 Aug 2025 12:21:46 +0000 (08:21 -0400)] 
Fixes: #12711 Added sparse vector support in Oracle
Extended :class:`_oracle.VECTOR` to support sparse vectors. This update
introduces :class:_oracle.VectorStorageType to specify sparse or dense
storage and added :class:`_oracle.SparseVector`. Pull request courtesy
Suraj Shaw.

Fixes: #12711
Closes: #12712
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12712
Pull-request-sha: 5a4199de1e89785129ee6fce4c7e65570419a1c7

Change-Id: Icdda9520a5f752e923f087edb166b4032f5bfd21

8 weeks agoensure autocommit is not False for SQLite FK pragma
Mike Bayer [Thu, 7 Aug 2025 14:48:51 +0000 (10:48 -0400)] 
ensure autocommit is not False for SQLite FK pragma

References: #12767
References: https://github.com/python/cpython/issues/137205
Change-Id: I6772a4c9c216c6981421043f850cbf833ded2be3

8 weeks agoMerge "implement skip_autocommit_rollback" into main
Michael Bayer [Thu, 7 Aug 2025 14:46:02 +0000 (14:46 +0000)] 
Merge "implement skip_autocommit_rollback" into main

8 weeks agoMerge "add chunking to selectin_polymorphic" into main
Michael Bayer [Wed, 6 Aug 2025 19:19:49 +0000 (19:19 +0000)] 
Merge "add chunking to selectin_polymorphic" into main

8 weeks agoimplement skip_autocommit_rollback
Mike Bayer [Tue, 5 Aug 2025 14:46:21 +0000 (10:46 -0400)] 
implement skip_autocommit_rollback

Added new parameter :paramref:`.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.

Fixes: #12784
Change-Id: I22b45ab2fc396c5aadeff5cdc5ce895144d00098

8 weeks agoadd chunking to selectin_polymorphic
Mike Bayer [Wed, 6 Aug 2025 14:19:39 +0000 (10:19 -0400)] 
add chunking to selectin_polymorphic

Improved the implementation of the :func:`_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
:func:`_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.

Fixes: #12790
Change-Id: I8df7f34d4fdf73996780772d983b72ea0fc8309e

8 weeks agoMerge "Fix use_existing_column with Annotated mapped_column in polymorphic inheritanc...
Michael Bayer [Wed, 6 Aug 2025 14:39:28 +0000 (14:39 +0000)] 
Merge "Fix use_existing_column with Annotated mapped_column in polymorphic inheritance" into main

2 months agoapply correct pre-fetch params to post updated rows
Mike Bayer [Tue, 5 Aug 2025 21:11:50 +0000 (17:11 -0400)] 
apply correct pre-fetch params to post updated rows

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
an :paramref:`.Column.onupdate` callable or a version id generator used by
:paramref:`.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.

Fixes: #12748
Change-Id: Id12c7973f168604533762dfc01afbb9155b693a6

2 months agoand now a word on AI
Mike Bayer [Tue, 5 Aug 2025 19:43:25 +0000 (15:43 -0400)] 
and now a word on AI

Change-Id: Ibec387d36bc08ea40c0e4c92bd5f2f79a54adaf7

2 months agoFix use_existing_column with Annotated mapped_column in polymorphic inheritance
Mike Bayer [Tue, 5 Aug 2025 18:05:49 +0000 (14:05 -0400)] 
Fix use_existing_column with Annotated mapped_column in polymorphic inheritance

Fixed issue where :paramref:`_orm.mapped_column.use_existing_column`
parameter in :func:`_orm.mapped_column` would not work when the
:func:`_orm.mapped_column` is used inside of an ``Annotated`` type alias in
polymorphic inheritance scenarios. The parameter is now properly recognized
and processed during declarative mapping configuration.

Fixes: #12787
Change-Id: I0505df3f3714434e98052c4488f6b1b1d2b1f755

2 months agoMerge "Fix PostgreSQL JSONB subscripting regression with functions" into main
Michael Bayer [Tue, 5 Aug 2025 18:13:59 +0000 (18:13 +0000)] 
Merge "Fix PostgreSQL JSONB subscripting regression with functions" into main

2 months agoMerge "cleanup implementation of asyncpg connection" into main
Michael Bayer [Mon, 4 Aug 2025 19:47:19 +0000 (19:47 +0000)] 
Merge "cleanup implementation of asyncpg connection" into main

2 months agoMerge "generalize composite bulk insert to hybrids" into main
Michael Bayer [Mon, 4 Aug 2025 19:44:36 +0000 (19:44 +0000)] 
Merge "generalize composite bulk insert to hybrids" into main

2 months agoMerge "add CRUD column marker" into main
Michael Bayer [Mon, 4 Aug 2025 19:41:56 +0000 (19:41 +0000)] 
Merge "add CRUD column marker" into main

2 months agoFix PostgreSQL JSONB subscripting regression with functions
Mike Bayer [Fri, 1 Aug 2025 16:48:15 +0000 (12:48 -0400)] 
Fix PostgreSQL JSONB subscripting regression with functions

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 of ``function_call[index]`` to comply
with PostgreSQL syntax requirements.

Fixes: #12778
Change-Id: If1238457e6bba6a933023b26519a41aa5de4dbcd

2 months agofix typo in docs
Federico Caselli [Thu, 31 Jul 2025 17:21:33 +0000 (19:21 +0200)] 
fix typo in docs

Change-Id: I327961111c4f785a1a21dfabbf620f9f8f8f5d90

2 months agoupdate install faq to align with code
Federico Caselli [Wed, 30 Jul 2025 20:36:35 +0000 (22:36 +0200)] 
update install faq to align with code

Closes #12757

Change-Id: I13b98a185fb4347cd172c6a6f95214672ae05fec

2 months agoremove obsolete file
Federico Caselli [Tue, 29 Jul 2025 20:17:27 +0000 (22:17 +0200)] 
remove obsolete file

Remove mypy_plugin.ini file that's no loger useful, since the mypy
plugin was removed in d69765829c9fbc98f21a22dbc496f2b7b22dc52c

Change-Id: I3f49a367b36b07e8cc1b10b415d6209de2eef3fb

2 months agoRemove unnecessary r-prefix from docstring in 'columns' method (#12768)
Sviatoslav Bobryshev [Tue, 29 Jul 2025 20:08:15 +0000 (23:08 +0300)] 
Remove unnecessary r-prefix from docstring in 'columns' method (#12768)

2 months agocherry-pick changelog update for 2.0.43
Mike Bayer [Tue, 29 Jul 2025 12:48:27 +0000 (08:48 -0400)] 
cherry-pick changelog update for 2.0.43

2 months agocherry-pick changelog from 2.0.42
Mike Bayer [Tue, 29 Jul 2025 12:48:27 +0000 (08:48 -0400)] 
cherry-pick changelog from 2.0.42

2 months agorepair changelog file
Mike Bayer [Tue, 29 Jul 2025 11:34:56 +0000 (07:34 -0400)] 
repair changelog file

Change-Id: I40994de5197271060e97a0bd7bccafc7c08918d8

2 months agoMerge "Add ``dataclass_metadata`` parameter to orm cols" into main
Michael Bayer [Tue, 29 Jul 2025 11:25:12 +0000 (11:25 +0000)] 
Merge "Add ``dataclass_metadata`` parameter to orm cols" into main

2 months agoMerge "Fix reflection of enum named intervalsomething" into main
Michael Bayer [Tue, 29 Jul 2025 11:21:12 +0000 (11:21 +0000)] 
Merge "Fix reflection of enum named intervalsomething" into main

2 months agoFix reflection of enum named intervalsomething
Federico Caselli [Mon, 21 Jul 2025 21:36:43 +0000 (23:36 +0200)] 
Fix reflection of enum named intervalsomething

Fixes bug that would mistakenly interpret a domain or enum type
with name starting in ``interval`` as an ``INTERVAL`` type while
reflecting a table.

Fixes: #12744
Change-Id: I89ab287c3847ca545691afe73f26d86bf2337ae0

2 months agoMerge "Add orderinglist type annotations" into main
Federico Caselli [Mon, 28 Jul 2025 12:29:24 +0000 (12:29 +0000)] 
Merge "Add orderinglist type annotations" into main

2 months agoMerge "type aiosqlite" into main
Federico Caselli [Mon, 28 Jul 2025 12:05:01 +0000 (12:05 +0000)] 
Merge "type aiosqlite" into main

2 months agoAdd orderinglist type annotations
Martijn Pieters [Mon, 25 Nov 2024 19:38:48 +0000 (14:38 -0500)] 
Add orderinglist type annotations

Closes: #10889
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10889
Pull-request-sha: 2ddeeb190630a8965a4fae567e2649ed16722c99

Change-Id: I9a0d6e2776d8b6756af4a3c54668bdcd1a1f40f8

2 months agocleanup implementation of asyncpg connection
Federico Caselli [Mon, 24 Mar 2025 21:44:05 +0000 (22:44 +0100)] 
cleanup implementation of asyncpg connection

Change-Id: Ic7ecbeb6341145544b2a501d287e3e1d30fb1cbc