Commit Graph

12099 Commits

Author SHA1 Message Date
Federico Caselli 084eac6916 Merge "improve overloads applied to generic functions" into main 2025-04-03 19:22:37 +00:00
Michael Bayer ecbd1228c2 Merge "ensure ON UPDATE test is case insensitive" into main 2025-04-02 16:32:35 +00:00
Alexander Ruehe 6f8f4a7d62 ensure ON UPDATE test is case insensitive
Fixed regression caused by the DEFAULT rendering changes in 2.0.40
🎫`12425` where using lowercase `on update` in a MySQL server default
would incorrectly apply parenthesis, leading to errors when MySQL
interpreted the rendered DDL.  Pull request courtesy Alexander Ruehe.

Fixes: #12488
Closes: #12489
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12489
Pull-request-sha: b9008f747d

Change-Id: If5281c52415e4ddb6c2f8aee191d2335f6673b35
2025-04-02 11:23:00 -04:00
Federico Caselli 0861969379 minor cleanup of postgresql index reflection query
Change-Id: I669ea8e99c6b69cb70263b0cacd80d3ed0fab39c
2025-04-01 23:49:36 +02:00
Federico Caselli 77d8609d7b Merge "Add type annotations to postgresql.pg_catalog" into main 2025-04-01 19:10:01 +00:00
Michael Bayer 451225588f Merge "Removed executable coercion" into main 2025-03-31 12:34:16 +00:00
Michael Bayer 77a6750efe Merge "Type array_agg()" into main 2025-03-27 16:34:35 +00:00
Michael Bayer 7fdada9c90 Merge "implement AsyncSessionTransaction._regenerate_proxy_for_target" into main 2025-03-27 16:29:58 +00:00
Mike Bayer 0202673a34 implement AsyncSessionTransaction._regenerate_proxy_for_target
Fixed issue where :meth:`.AsyncSession.get_transaction` and
:meth:`.AsyncSession.get_nested_transaction` would fail with
``NotImplementedError`` if the "proxy transaction" used by
:class:`.AsyncSession` were garbage collected and needed regeneration.

Fixes: #12471
Change-Id: Ia8055524618df706d7958786a500cdd25d9d8eaf
2025-03-27 11:11:04 -04:00
Kaan 7e28adbe0c Implement GROUPS frame spec for window functions
Implemented support for the GROUPS frame specification in window functions
by adding :paramref:`_sql.over.groups` option to :func:`_sql.over`
and :meth:`.FunctionElement.over`. Pull request courtesy Kaan Dikmen.

Fixes: #12450
Closes: #12445
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12445
Pull-request-sha: c0808e135f

Change-Id: I9ff504a9c9650485830c4a0eaf44162898a3a2ad
2025-03-27 13:34:52 +00:00
Michael Bayer 94c0976ad3 Merge "compatibility with typing_extensions 4.13 and type statement" into main 2025-03-27 13:33:30 +00:00
Daraan 690e754b65 compatibility with typing_extensions 4.13 and type statement
Fixed regression caused by ``typing_extension==4.13.0`` that introduced
a different implementation for ``TypeAliasType`` while SQLAlchemy assumed
that it would be equivalent to the ``typing`` version.

Added test regarding generic TypeAliasType

Fixes: #12473
Closes: #12472
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12472
Pull-request-sha: 8861a5acfb

Change-Id: I053019a222546a625ed6d588314ae9f5b34c2f8a
2025-03-27 00:36:23 +01:00
Federico Caselli a9b3719913 document sqlite truncate_microseconds in DATETIME and TIME
Change-Id: I93412d951b466343f2cf9b6d513ad46d17f5d8ee
2025-03-26 21:43:10 +01:00
Federico Caselli 5cc6a65c61 improve overloads applied to generic functions
try again to remove the overloads to the generic functionn
generator (like coalesce, array_agg, etc).
As of mypy 1.15 it still does now work, but a simpler version
is added in this change

Change-Id: I8b97ae00298ec6f6bf8580090e5defff71e1ceb0
2025-03-25 23:39:05 +01:00
Stefanie Molin aae34df0b5 Add missing imports to example (#12453) 2025-03-25 20:05:44 +01:00
Denis Laxalde 864f79d7c4 Add type annotations to postgresql.pg_catalog
Related to #6810.

Closes: #12462
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12462
Pull-request-sha: 5a131cc9a9

Change-Id: Ie4494d61f815edefef6a896499db4292fd94a22a
2025-03-25 04:51:30 -04:00
Denis Laxalde 543acbd8d1 Type array_agg()
The return type of `array_agg()` is declared as a `Sequence[T]` where `T` is bound to the type of input argument.

This is implemented by making `array_agg()` inheriting from `ReturnTypeFromArgs` which provides appropriate overloads of `__init__()` to support this.

This usage of ReturnTypeFromArgs is a bit different from previous ones as the return type of the function is not exactly the same as that of its arguments, but a "collection" (a generic, namely a Sequence here) of the argument types.  Accordingly, we adjust the code of `tools/generate_sql_functions.py` to retrieve the "collection" type from 'fn_class' annotation and generate expected return type.

Also add a couple of hand-written typing tests for PostgreSQL.

Related to #6810

Closes: #12461
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12461
Pull-request-sha: ba27cbb863

Change-Id: I3fd538cc7092a0492c26970f0b825bf70ddb66cd
2025-03-24 22:22:35 +01:00
Michael Bayer dabd77992d Merge "Cast empty PostgreSQL ARRAY from the type specified to array()" into main 2025-03-20 01:41:54 +00:00
Michael Bayer 0db547f6ab Merge "skip FROM disambiguation for immediate alias of table" into main 2025-03-19 23:58:23 +00:00
Denis Laxalde 588cc6ed8e Cast empty PostgreSQL ARRAY from the type specified to array()
When building a PostgreSQL ``ARRAY`` literal using
:class:`_postgresql.array` with an empty ``clauses`` argument, the
:paramref:`_postgresql.array.type_` parameter is now significant in that it
will be used to render the resulting ``ARRAY[]`` SQL expression with a
cast, such as ``ARRAY[]::INTEGER``. Pull request courtesy Denis Laxalde.

Fixes: #12432
Closes: #12435
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12435
Pull-request-sha: 9633d3c15d

Change-Id: I29ed7bd0562b82351d22de0658fb46c31cfe44f6
2025-03-19 19:32:09 -04:00
Michael Bayer 31485a778f Merge "Make ARRAY generic on the item_type" into main 2025-03-19 22:43:18 +00:00
Mike Bayer 9ea3be0681 skip FROM disambiguation for immediate alias of table
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.

Fixes: #12451
Change-Id: I981823f8f2cdf3992d65ace93a21fc20d1d74cda
2025-03-19 18:30:21 -04:00
Mike Bayer c86ebb0a99 implement use_descriptor_defaults for dataclass defaults
A significant behavioral change has been made to the behavior of the
:paramref:`_orm.mapped_column.default` and
:paramref:`_orm.relationship.default` parameters, when used with
SQLAlchemy's :ref:`orm_declarative_native_dataclasses` feature introduced
in 2.0, where the given value (assumed to be an immutable scalar value) is
no longer passed to the ``@dataclass`` API as a real default, instead a
token that leaves the value un-set in the object's ``__dict__`` is used, in
conjunction with a descriptor-level default.  This prevents an un-set
default value from overriding a default that was actually set elsewhere,
such as in relationship / foreign key assignment patterns as well as in
:meth:`_orm.Session.merge` scenarios.   See the full writeup in the
:ref:`whatsnew_21_toplevel` document which includes guidance on how to
re-enable the 2.0 version of the behavior if needed.

This adds a new implicit default field to ScalarAttributeImpl
so that we can have defaults that are not in the dictionary but
are instead passed through to the class-level descriptor, effectively
allowing custom defaults that are not used in INSERT or merge

Fixes: #12168
Change-Id: Ia327d18d6ec47c430e926ab7658e7b9f0666206e
2025-03-19 15:14:37 -04:00
Denis Laxalde 500adfafcb Make ARRAY generic on the item_type
Now `Column(type_=ARRAY(Integer)` is inferred as `Column[Sequence[int]]` instead as `Column[Sequence[Any]]` previously. This only works with the `type_` argument to Column, but that's not new.

This follows from a suggestion at
https://github.com/sqlalchemy/sqlalchemy/pull/12386#issuecomment-2694056069.

Related to #6810.

Closes: #12443
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12443
Pull-request-sha: 2fff4e89cd

Change-Id: I87b828fd82d10fbf157141db3c31f0ec8149caad
2025-03-18 12:23:01 -04:00
Michael Bayer a385bd9b50 Merge "remove deprecated features" into main 2025-03-18 16:12:15 +00:00
Federico Caselli 1ebd8c525b remove deprecated features
Remove feature deprecates in 1.3 and before

Fixes: #12441
Change-Id: Ice3d35ec02988ce94cdeb9db41cb684db2fb5d8d
2025-03-18 09:17:07 -04:00
Michael Bayer fd6c08f403 Merge "add postgresql distinct_on (patch 4)" into main 2025-03-18 13:00:56 +00:00
Michael Bayer 39ef84ee93 Merge "expand paren rules for default rendering, sqlite/mysql" into main 2025-03-18 12:17:26 +00:00
Michael Bayer ae22153484 Merge "ensure SQL expressions w/o bool pass through to correct typing error" into main 2025-03-18 01:50:41 +00:00
Mike Bayer b19a09812c ensure SQL expressions w/o bool pass through to correct typing error
Fixed regression which occurred as of 2.0.37 where the checked
:class:`.ArgumentError` that's raised when an inappropriate type or object
is used inside of a :class:`.Mapped` annotation would raise ``TypeError``
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 the :class:`.Mapped` construct, these scenarios have all been unified
under a new subclass of :class:`.ArgumentError` called
:class:`.MappedAnnotationError`, to provide some continuity between these
different scenarios, even though specific messaging remains distinct.

Fixes: #12329
Change-Id: I0193e3479c84a48b364df8655f050e2e84151122
2025-03-17 18:26:23 -04:00
Michael Bayer d7ac4b819e Merge "Support column list for foreign key ON DELETE SET actions on PostgreSQL" into main 2025-03-17 21:30:45 +00:00
Michael Bayer 17af9bacc4 Merge "remove non_primary parameter" into main 2025-03-17 21:18:49 +00:00
Mike Bayer 5f8ac70996 add postgresql distinct_on (patch 4)
Added syntax extension :func:`_postgresql.distinct_on` to build ``DISTINCT
ON`` clauses. The old api, that passed columns to
:meth:`_sql.Select.distinct`, is now deprecated.

Fixes: #12342
Change-Id: Ia6a7e647a11e57b6ac2f50848778c20dc55eaf54
2025-03-17 15:51:21 -04:00
Mike Bayer 1afb820427 expand paren rules for default rendering, sqlite/mysql
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.

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.

Fixes: #12425
Change-Id: Ie40703dcd5fdc135025d676c01baba57ff3b71ad
2025-03-17 15:02:30 -04:00
Denis Laxalde 39bb17442c Support column list for foreign key ON DELETE SET actions on PostgreSQL
Added support for specifying a list of columns for ``SET NULL`` and ``SET
DEFAULT`` actions of ``ON DELETE`` clause of foreign key definition on
PostgreSQL.  Pull request courtesy Denis Laxalde.

Fixes: #11595
Closes: #12421
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12421
Pull-request-sha: d0394db706

Change-Id: I036a559ae4a8efafe9ba64d776a840bd785a7397
2025-03-17 14:02:24 -04:00
Michael Bayer 1d49add435 Merge "miscellaneous to type dialects" into main 2025-03-17 17:35:20 +00:00
Michael Bayer 6b2111f374 Merge "Removes old version added and change notes" into main 2025-03-17 17:31:19 +00:00
Michael Bayer f6e42a0f64 Merge "Add type annotations to postgresql.array" into main 2025-03-17 17:29:31 +00:00
Mike Bayer 5ec437a905 remove non_primary parameter
The "non primary" mapper feature, long deprecated in SQLAlchemy since
version 1.3, has been removed.   The sole use case for "non primary"
mappers was that of using :func:`_orm.relationship` to link to a mapped
class against an alternative selectable; this use case is now suited by the
:doc:`relationship_aliased_class` feature.

Fixes: #12437
Change-Id: I6987da06beb1d88d6f6e9696ce93e7fc340fc0ef
2025-03-17 12:58:46 -04:00
Federico Caselli cc1982f4a1 Removes old version added and change notes
Removes documentation notes for changes and addition prior to 1.3
included.

Change-Id: Ibabb5222ccafa0c27c8ec40e31b149707d9c8aa3
2025-03-16 22:32:10 +01:00
Denis Laxalde 75c8e112c9 Add type annotations to postgresql.array
Improved static typing for `postgresql.array()` by making the type parameter (the type of array's elements) inferred from the `clauses` and `type_` arguments while also ensuring they are consistent.

Also completed type annotations of `postgresql.ARRAY` following commit 0bf7e02afb and added type annotations for functions `postgresql.Any()` and `postgresql.All()`.

Finally, fixed shadowing `typing.Any` by the `Any()` function through aliasing as `typing_Any`.

Related to #6810

Closes: #12384
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12384
Pull-request-sha: 78eea29f1d

Change-Id: I5d35d15ec8ba4d58eeb9bf00abb710e2e585731f
2025-03-15 16:21:27 +01:00
Pablo Estevez 0ee4b08b11 miscellaneous to type dialects
Type of certain methods that are called by dialect, so typing dialects is easier.

Related to https://github.com/sqlalchemy/sqlalchemy/pull/12164

breaking changes:

- Change modifiers from TextClause to InmutableDict, from Mapping, as is in the other classes

Closes: #12231
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12231
Pull-request-sha: 514fe4751c

Change-Id: I29314045b2c7eb5428f8d6fec8911c4b6d5ae73e
2025-03-15 15:12:27 +01:00
Mike Bayer ec20f346a6 anonymize CRUD params if visiting_cte is present
Fixed issue in :class:`.CTE` constructs involving multiple DDL
:class:`.Insert` statements with multiple VALUES parameter sets where the
bound parameter names generated for these parameter sets would conflict,
generating a compile time error.

Fixes: #12363
Change-Id: If8344ff725d4e0ec58d3ff61f38a0edcfc5bdebd
2025-03-14 10:33:22 -04:00
Michael Bayer bceff0e9e6 Merge "re-support mysql-connector python" into main 2025-03-14 12:58:23 +00:00
Michael Bayer 0c81857446 Merge "Complement type annotations for ARRAY" into main 2025-03-13 15:27:25 +00:00
Michael Bayer a8ac6ae23c Merge "Ensure PostgreSQL network address types are not cast as VARCHAR" into main 2025-03-11 18:07:05 +00:00
Denis Laxalde f91e61e5c8 Ensure PostgreSQL network address types are not cast as VARCHAR
Fixed issue in PostgreSQL network types :class:`_postgresql.INET`,
:class:`_postgresql.CIDR`, :class:`_postgresql.MACADDR`,
:class:`_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.

Fixes: #12060
Closes: #12412
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12412
Pull-request-sha: 029fda7f2d

Change-Id: Id4a502ebc119775567cacddbabef2ce9715c1a9f
2025-03-11 10:05:39 -04:00
Mike Bayer 21630d2574 consolidate kwargs for "FOR UPDATE OF"
Fixed compiler issue in the PostgreSQL dialect where incorrect keywords
would be passed when using "FOR UPDATE OF" inside of a subquery.

Fixes: #12417
Change-Id: I6255d165e8e719e1786e78aa60ee8e6a95af1dcb
2025-03-11 08:36:18 -04:00
Mike Bayer b056dd2c5a re-support mysql-connector python
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
Change-Id: I81279478196e830d3c0d5f24ecb3fe2dc18d4ca6
2025-03-10 14:04:21 -04:00
Michael Bayer dfc3bf988b Merge "restate all upsert in terms of statement extensions (patch 3)" into main 2025-03-07 15:09:00 +00:00