]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/log
thirdparty/sqlalchemy/sqlalchemy.git
2 months agoMerge "add correct typing for row getitem" into main
Michael Bayer [Thu, 1 May 2025 13:26:10 +0000 (13:26 +0000)] 
Merge "add correct typing for row getitem" into main

2 months agoadd correct typing for row getitem
Federico Caselli [Mon, 28 Apr 2025 21:44:50 +0000 (23:44 +0200)] 
add correct typing for row getitem

The overloads were broken in 8a4c27589500bc57605bb8f28c215f5f0ae5066d

Change-Id: I3736b15e95ead28537e25169a54521e991f763da

2 months agoFix simple typo (#12555)
Ross Patterson [Tue, 29 Apr 2025 20:14:09 +0000 (13:14 -0700)] 
Fix simple typo (#12555)

2 months agoMerge "refactor (orm): remove unused variables and simplify key lookups" into main
Federico Caselli [Sun, 27 Apr 2025 19:43:33 +0000 (19:43 +0000)] 
Merge "refactor (orm): remove unused variables and simplify key lookups" into main

2 months agorefactor (orm): remove unused variables and simplify key lookups
Federico Caselli [Thu, 24 Apr 2025 22:02:32 +0000 (18:02 -0400)] 
refactor (orm): remove unused variables and simplify key lookups

Redundant variables and unnecessary conditions were removed across several modules. Improved readability and reduced code complexity without changing functionality.

Closes: #12537
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12537
Pull-request-sha: ab53f8c3487e8cfb4d4a0235c27d8a5b8557d193

Change-Id: I910d65729fdbc96933f9822c553924d37e89e201

2 months agofix reference cycles/ perf in DialectKWArgs
Mike Bayer [Sat, 26 Apr 2025 15:32:30 +0000 (11:32 -0400)] 
fix reference cycles/ perf in DialectKWArgs

Identified some unnecessary cycles and overhead in how
this is implemented.  since we want to add this to Select,
needs these improvements.

Change-Id: I4324db14aaf52ab87a8b7fa49ebf1b6624bc2dcb

2 months agoMerge "refactor(testing-and-utils): Remove unused code and fix style issues" into...
Federico Caselli [Thu, 24 Apr 2025 21:51:04 +0000 (21:51 +0000)] 
Merge "refactor(testing-and-utils): Remove unused code and fix style issues" into main

2 months agoMerge "refactor: clean up unused variables in engine module" into main
Federico Caselli [Thu, 24 Apr 2025 21:50:31 +0000 (21:50 +0000)] 
Merge "refactor: clean up unused variables in engine module" into main

2 months agoMerge "refactor (sql): simplify and optimize internal SQL handling" into main
Federico Caselli [Thu, 24 Apr 2025 21:49:58 +0000 (21:49 +0000)] 
Merge "refactor (sql): simplify and optimize internal SQL handling" into main

2 months agoMerge "refactor: simplify and clean up dialect-specific code" into main
Federico Caselli [Thu, 24 Apr 2025 20:32:06 +0000 (20:32 +0000)] 
Merge "refactor: simplify and clean up dialect-specific code" into main

2 months agoUpdate entry for sqlalchemy-hana (#12553)
Christoph Heer [Thu, 24 Apr 2025 20:00:52 +0000 (22:00 +0200)] 
Update entry for sqlalchemy-hana (#12553)

2 months agoAdd pow operator support
Federico Caselli [Fri, 4 Apr 2025 20:23:31 +0000 (22:23 +0200)] 
Add pow operator support

Added support for the pow operator (``**``), with a default SQL
implementation of the ``POW()`` function.   On Oracle Database, PostgreSQL
and MSSQL it renders as ``POWER()``.   As part of this change, the operator
routes through a new first class ``func`` member :class:`_functions.pow`,
which renders on Oracle Database, PostgreSQL and MSSQL as ``POWER()``.

Fixes: #8579
Closes: #8580
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8580
Pull-request-sha: 041b2ef474a291c6b6172e49cc6e0d548e28761a

Change-Id: I371bd44ed3e58f2d55ef705aeec7d04710c97f23

2 months agoMerge "optimize `@util.decorator`" into main
Michael Bayer [Mon, 21 Apr 2025 23:08:40 +0000 (23:08 +0000)] 
Merge "optimize `@util.decorator`" into main

2 months agorefactor (sql): simplify and optimize internal SQL handling
Shamil [Mon, 21 Apr 2025 16:36:21 +0000 (12:36 -0400)] 
refactor (sql): simplify and optimize internal SQL handling

Replaced redundant variable assignments with direct operations. Used `dict.get()` for safer dictionary lookups to streamline logic. Improves code readability and reduces unnecessary lines.

Closes: #12538
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12538
Pull-request-sha: d322d1508cfc37668099e6624816aba9c647ad51

Change-Id: Ib3dfc7086ec35117fdad65e136a17aa014b96ae5

2 months agorefactor(testing-and-utils): Remove unused code and fix style issues
Shamil [Mon, 21 Apr 2025 16:35:43 +0000 (12:35 -0400)] 
refactor(testing-and-utils): Remove unused code and fix style issues

This PR includes several small refactorings and style fixes aimed at improving code cleanliness, primarily within the test suite and tooling.

Key changes:

*   Removed assignments to unused variables in various test files (`test_dialect.py`, `test_reflection.py`, `test_select.py`).
*   Removed an unused variable in the pytest plugin (`pytestplugin.py`).
*   Removed an unused variable in the topological sort utility (`topological.py`).
*   Fixed a minor style issue (removed an extra blank line) in the `cython_imports.py` script.

Closes: #12539
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12539
Pull-request-sha: 837c1e6cb17f0ff31444d5161329c318b52e48e7

Change-Id: Ifa37fb956bc3cacd31967f08bdaa4254e16911c2

2 months agorefactor: clean up unused variables in engine module
Shamil [Thu, 17 Apr 2025 19:48:19 +0000 (15:48 -0400)] 
refactor: clean up unused variables in engine module

Removed unused variables to improve code clarity and maintainability. This change simplifies logic in `base.py`, `default.py`, and `result.py`. No functionality was altered.

Closes: #12535
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12535
Pull-request-sha: a9d849f3a4f3abe9aff49279c4cc81aa26aeaa9b

Change-Id: If78b18dbd33733c631f8b5aad7d55261fbc4817b

2 months agorefactor: simplify and clean up dialect-specific code
Shamil [Thu, 17 Apr 2025 15:23:21 +0000 (11:23 -0400)] 
refactor: simplify and clean up dialect-specific code

**Title:** Removed unused variables and redundant functions across multiple dialects. Improves code readability and reduces maintenance complexity without altering functionality.
### Description
This pull request introduces several minor refactorings across different dialect modules:
- **MSSQL:**
    - Simplified the initialization of the `fkeys` dictionary in `_get_foreign_keys` using `util.defaultdict` directly.

- **MySQL:** Removed the unused variable in `_get_table_comment`. `rp`
- **PostgreSQL (_psycopg_common):** Removed the unused variable `cursor` in `do_ping`.
- **PostgreSQL (base):** Removed the unused variable `args` in `_get_column_info`.
- **SQLite:** Removed the unused variable `new_filename` in `generate_driver_url`.

These changes focus purely on code cleanup and simplification, removing dead code and improving clarity. They do not alter the existing logic or functionality of the dialects.
### Checklist
This pull request is:
- [ ] A documentation / typographical / small typing error fix
- [x] A short code fix
    - _Note: This is a general cleanup refactor rather than a fix for a specific reported issue._

- [ ] A new feature implementation

**Have a nice day!**

Closes: #12534
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12534
Pull-request-sha: 2c7ae17b73192ba6bff6bec953b307a88ea31847

Change-Id: I1ec3b48f42aea7e45bc20f81add03051eb30bb98

2 months agodisable mysql/connector-python, again
Mike Bayer [Mon, 21 Apr 2025 13:44:40 +0000 (09:44 -0400)] 
disable mysql/connector-python, again

Just as we got this driver "working", a new regression is introduced
in version 9.3.0 which prevents basic binary string persistence [1].
I would say we need to leave this driver off for another few years
until something changes with its upstream maintenance.

[1] https://bugs.mysql.com/bug.php?id=118025

Change-Id: If876f63ebb9a6f7dfa0b316df044afa469a154f2

2 months agochore: add type hint for reconstructor (#12527)
Ryu Juheon [Thu, 17 Apr 2025 19:48:54 +0000 (04:48 +0900)] 
chore: add type hint for reconstructor (#12527)

* chore: add type hint for reconstructor

* chore: fix attr-defined

* chore: use defined typevar

* chore: ignore type error

2 months agochore: Fix typo of psycopg2 in comment (#12526)
Matt John [Tue, 15 Apr 2025 19:05:36 +0000 (20:05 +0100)] 
chore: Fix typo of psycopg2 in comment (#12526)

This is the first example in the documentation of a particular connector, which mgith result in copy+pastes, resulting in an error

2 months agoMerge "Type postgresql.aggregate_order_by()" into main
Federico Caselli [Thu, 10 Apr 2025 22:32:29 +0000 (22:32 +0000)] 
Merge "Type postgresql.aggregate_order_by()" into main

2 months agoMerge "simplify internal storage of DML ordered values" into main
Michael Bayer [Thu, 10 Apr 2025 15:07:52 +0000 (15:07 +0000)] 
Merge "simplify internal storage of DML ordered values" into main

2 months agosimplify internal storage of DML ordered values
Mike Bayer [Tue, 8 Apr 2025 01:41:29 +0000 (21:41 -0400)] 
simplify internal storage of DML ordered values

towards some refactorings I will need to do for #12496, this
factors out the "_ordered_values" list of tuples that was used to
track UPDATE VALUES in a specific order.   The rationale for this
separate collection was due to Python dictionaries not maintaining
insert order.   Now that this is standard behavior in Python 3
we can use the same `statement._values` for param-ordered and
table-column-ordered UPDATE rendering.

Change-Id: Id6024ab06e5e3ba427174e7ba3630ff83d81f603

2 months agoType postgresql.aggregate_order_by()
Denis Laxalde [Wed, 9 Apr 2025 07:04:20 +0000 (03:04 -0400)] 
Type postgresql.aggregate_order_by()

Overloading of `__init__()` is needed, probably for the same reason as it is in `ReturnTypeFromArgs`.

Related to #6810.

Closes: #12463
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12463
Pull-request-sha: 701d979e20c6ca3e32b79145c20441407007122f

Change-Id: I7e1bb4d2c48dfb3461725c7079aaa72c66f1dc03

2 months agoorm.exc.NoResultFound => exc.NoResultFound (#12509)
Inada Naoki [Tue, 8 Apr 2025 20:43:25 +0000 (05:43 +0900)] 
orm.exc.NoResultFound => exc.NoResultFound (#12509)

* s/orm.exc.NoResultFound/exc.NoResultFound/

* use _exc

2 months agooptimize `@util.decorator`
Inada Naoki [Mon, 7 Apr 2025 23:55:48 +0000 (19:55 -0400)] 
optimize `@util.decorator`

### Description

util.decorator uses code generation + eval to create signature matching wrapper.
It consumes some CPU because we can not use pyc cache.

Additionally, each wrapped function has own globals for function annotations.

By stripping function annotations from eval-ed code, compile time and memory usage are saved.

```python
from sqlalchemy.util import decorator
from sqlalchemy import *
import timeit
import tracemalloc
import sqlalchemy.orm._orm_constructors

@decorator
def with_print(fn, *args, **kwargs):
    res = fn(*args, **kwargs)
    print(f"{fn.__name__}(*{args}, **{kwargs}) => {res}")
    return res

# test
PI = 3.14

def f():
    @with_print
    def add(x: int|float, *, y: int|float=PI) -> int|float:
        return x + y
    return add

add = f()
add(1)
print(add.__annotations__)

# benchmark
print(timeit.timeit(f, number=1000)*1000, "us")

# memory
tracemalloc.start(1)
[f() for _ in range(1000)]
mem, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
print(f"{mem=}, {peak=}")
```

Result:
```
$ .venv/bin/python -VV
Python 3.14.0a6 (main, Mar 17 2025, 21:27:10) [Clang 20.1.0 ]

$ .venv/bin/python sample.py
add(*(1,), **{'y': 3.14}) => 4.140000000000001
{'x': int | float, 'y': int | float, 'return': int | float}
35.93937499681488 us
mem=9252896, peak=9300808

$ git switch -
Switched to branch 'opt-decorator'

$ .venv/bin/python sample.py
add(*(1,), **{'y': 3.14}) => 4.140000000000001
{'x': int | float, 'y': int | float, 'return': int | float}
23.32574996398762 us
mem=1439032, peak=1476423
```

### 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:

- [ ] A documentation / typographical / small typing error fix
- Good to go, no issue or tests are needed
- [x] 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.

Closes: #12502
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12502
Pull-request-sha: 34409cbbfd2dee65bf86a85a87e415c9af47dc62

Change-Id: I88b88eb6eb018608bc2881459f58564881d06641

3 months agoMerge "Support postgresql_include in UniqueConstraint and PrimaryKeyConstraint" into...
Federico Caselli [Fri, 4 Apr 2025 19:04:01 +0000 (19:04 +0000)] 
Merge "Support postgresql_include in UniqueConstraint and PrimaryKeyConstraint" into main

3 months agoMerge "improve overloads applied to generic functions" into main
Federico Caselli [Thu, 3 Apr 2025 19:22:37 +0000 (19:22 +0000)] 
Merge "improve overloads applied to generic functions" into main

3 months agodocs: Fix substr function starting index in hybrid_property example (#12482)
krave1986 [Thu, 3 Apr 2025 18:55:36 +0000 (02:55 +0800)] 
docs: Fix substr function starting index in hybrid_property example (#12482)

3 months agoFix typo (#12495)
Adriaan Joubert [Thu, 3 Apr 2025 17:56:29 +0000 (20:56 +0300)] 
Fix typo (#12495)

3 months agoMerge "ensure ON UPDATE test is case insensitive" into main
Michael Bayer [Wed, 2 Apr 2025 16:32:35 +0000 (16:32 +0000)] 
Merge "ensure ON UPDATE test is case insensitive" into main

3 months agoensure ON UPDATE test is case insensitive
Alexander Ruehe [Tue, 1 Apr 2025 21:52:12 +0000 (17:52 -0400)] 
ensure ON UPDATE test is case insensitive

Fixed regression caused by the DEFAULT rendering changes in 2.0.40
:ticket:`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: b9008f747d21bc06a4006c99a47fc6aa99407636

Change-Id: If5281c52415e4ddb6c2f8aee191d2335f6673b35

3 months agominor cleanup of postgresql index reflection query
Federico Caselli [Tue, 1 Apr 2025 21:49:36 +0000 (23:49 +0200)] 
minor cleanup of postgresql index reflection query

Change-Id: I669ea8e99c6b69cb70263b0cacd80d3ed0fab39c

3 months agoSupport postgresql_include in UniqueConstraint and PrimaryKeyConstraint
Denis Laxalde [Tue, 1 Apr 2025 17:30:48 +0000 (13:30 -0400)] 
Support postgresql_include in UniqueConstraint and PrimaryKeyConstraint

This is supported both for schema definition and reflection.

Fixes #10665.

Closes: #12485
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12485
Pull-request-sha: 1aabea7b55ece9fc0c6e069b777d4404ac01f964

Change-Id: I81d23966f84390dd1b03f0d13284ce6d883ee24e

3 months agoMerge "Add type annotations to postgresql.pg_catalog" into main
Federico Caselli [Tue, 1 Apr 2025 19:10:01 +0000 (19:10 +0000)] 
Merge "Add type annotations to postgresql.pg_catalog" into main

3 months agoMerge "Removed executable coercion" into main
Michael Bayer [Mon, 31 Mar 2025 12:34:16 +0000 (12:34 +0000)] 
Merge "Removed executable coercion" into main

3 months agocherry-pick changelog update for 2.0.41
Mike Bayer [Thu, 27 Mar 2025 17:52:56 +0000 (13:52 -0400)] 
cherry-pick changelog update for 2.0.41

3 months agocherry-pick changelog from 2.0.40
Mike Bayer [Thu, 27 Mar 2025 17:52:56 +0000 (13:52 -0400)] 
cherry-pick changelog from 2.0.40

3 months agochangelog update
Mike Bayer [Thu, 27 Mar 2025 16:47:43 +0000 (12:47 -0400)] 
changelog update

Change-Id: I03202183f4045030bc2940c43d637edc3524b5d4

3 months agoMerge "Type array_agg()" into main
Michael Bayer [Thu, 27 Mar 2025 16:34:35 +0000 (16:34 +0000)] 
Merge "Type array_agg()" into main

3 months agoMerge "implement AsyncSessionTransaction._regenerate_proxy_for_target" into main
Michael Bayer [Thu, 27 Mar 2025 16:29:58 +0000 (16:29 +0000)] 
Merge "implement AsyncSessionTransaction._regenerate_proxy_for_target" into main

3 months agoimplement AsyncSessionTransaction._regenerate_proxy_for_target
Mike Bayer [Wed, 26 Mar 2025 17:55:46 +0000 (13:55 -0400)] 
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

3 months agoImplement GROUPS frame spec for window functions
Kaan [Wed, 19 Mar 2025 15:58:30 +0000 (11:58 -0400)] 
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: c0808e135f15c7fef3a3abcf28465673f38eb428

Change-Id: I9ff504a9c9650485830c4a0eaf44162898a3a2ad

3 months agoMerge "compatibility with typing_extensions 4.13 and type statement" into main
Michael Bayer [Thu, 27 Mar 2025 13:33:30 +0000 (13:33 +0000)] 
Merge "compatibility with typing_extensions 4.13 and type statement" into main

3 months agocompatibility with typing_extensions 4.13 and type statement
Daraan [Wed, 26 Mar 2025 18:27:46 +0000 (14:27 -0400)] 
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: 8861a5acfb8e81663413ff144b41abf64779b6fd

Change-Id: I053019a222546a625ed6d588314ae9f5b34c2f8a

3 months agodocument sqlite truncate_microseconds in DATETIME and TIME
Federico Caselli [Wed, 26 Mar 2025 20:43:10 +0000 (21:43 +0100)] 
document sqlite truncate_microseconds in DATETIME and TIME

Change-Id: I93412d951b466343f2cf9b6d513ad46d17f5d8ee

3 months agoMerge "Increase minimum required greenlet version" into main
Federico Caselli [Wed, 26 Mar 2025 12:09:01 +0000 (12:09 +0000)] 
Merge "Increase minimum required greenlet version" into main

3 months agoimprove overloads applied to generic functions
Federico Caselli [Mon, 24 Mar 2025 20:50:45 +0000 (21:50 +0100)] 
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

3 months agoIncrease minimum required greenlet version
Chris Withers [Tue, 25 Mar 2025 19:05:23 +0000 (15:05 -0400)] 
Increase minimum required greenlet version

Add a lower bound constraint on the greenlet version to 1.

Closes: #12459
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12459
Pull-request-sha: 4bd856b9c164df984f05c094c977686470ed4244

Change-Id: I200861f1706bf261c2e586b96e8cc35dceb7670b

3 months agoAdd missing imports to example (#12453)
Stefanie Molin [Tue, 25 Mar 2025 19:05:44 +0000 (15:05 -0400)] 
Add missing imports to example (#12453)

3 months agoAdd type annotations to postgresql.pg_catalog
Denis Laxalde [Tue, 25 Mar 2025 08:51:30 +0000 (04:51 -0400)] 
Add type annotations to postgresql.pg_catalog

Related to #6810.

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

Change-Id: Ie4494d61f815edefef6a896499db4292fd94a22a

3 months agoType array_agg()
Denis Laxalde [Mon, 24 Mar 2025 20:35:07 +0000 (16:35 -0400)] 
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: ba27cbb8639dcd35127ab6a2928b7b5b3667e287

Change-Id: I3fd538cc7092a0492c26970f0b825bf70ddb66cd

3 months agoMerge "Cast empty PostgreSQL ARRAY from the type specified to array()" into main
Michael Bayer [Thu, 20 Mar 2025 01:41:54 +0000 (01:41 +0000)] 
Merge "Cast empty PostgreSQL ARRAY from the type specified to array()" into main

3 months agoMerge "skip FROM disambiguation for immediate alias of table" into main
Michael Bayer [Wed, 19 Mar 2025 23:58:23 +0000 (23:58 +0000)] 
Merge "skip FROM disambiguation for immediate alias of table" into main

3 months agoCast empty PostgreSQL ARRAY from the type specified to array()
Denis Laxalde [Wed, 19 Mar 2025 08:17:27 +0000 (04:17 -0400)] 
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: 9633d3c15d42026f8f45f5a4d201a5d72e57b8d4

Change-Id: I29ed7bd0562b82351d22de0658fb46c31cfe44f6

3 months agoMerge "Make ARRAY generic on the item_type" into main
Michael Bayer [Wed, 19 Mar 2025 22:43:18 +0000 (22:43 +0000)] 
Merge "Make ARRAY generic on the item_type" into main

3 months agoMerge "implement use_descriptor_defaults for dataclass defaults" into main
Michael Bayer [Wed, 19 Mar 2025 22:42:36 +0000 (22:42 +0000)] 
Merge "implement use_descriptor_defaults for dataclass defaults" into main

3 months agoskip FROM disambiguation for immediate alias of table
Mike Bayer [Wed, 19 Mar 2025 22:30:21 +0000 (18:30 -0400)] 
skip FROM disambiguation for immediate alias of table

Fixed regression caused by :ticket:`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

3 months agoimplement use_descriptor_defaults for dataclass defaults
Mike Bayer [Tue, 10 Dec 2024 15:59:25 +0000 (10:59 -0500)] 
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

3 months agoremove attrs w/ orm annotated declarative example
Mike Bayer [Wed, 19 Mar 2025 12:59:54 +0000 (08:59 -0400)] 
remove attrs w/ orm annotated declarative example

as pointed out at
https://github.com/sqlalchemy/sqlalchemy/discussions/12449, ORM
annotated declarative is not compatible with attrs, declarative
cannot be used with attrs.

Change-Id: Ief6d1dca65b96164f48264a999c85bcae8dc3bb1

3 months agoMake ARRAY generic on the item_type
Denis Laxalde [Tue, 18 Mar 2025 16:23:01 +0000 (12:23 -0400)] 
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: 2fff4e89cd0b72d9444ce3f3d845b152770fc55d

Change-Id: I87b828fd82d10fbf157141db3c31f0ec8149caad

3 months agoMerge "remove deprecated features" into main
Michael Bayer [Tue, 18 Mar 2025 16:12:15 +0000 (16:12 +0000)] 
Merge "remove deprecated features" into main

3 months agoremove deprecated features
Federico Caselli [Sun, 16 Mar 2025 21:31:09 +0000 (22:31 +0100)] 
remove deprecated features

Remove feature deprecates in 1.3 and before

Fixes: #12441
Change-Id: Ice3d35ec02988ce94cdeb9db41cb684db2fb5d8d

3 months agoMerge "add postgresql distinct_on (patch 4)" into main
Michael Bayer [Tue, 18 Mar 2025 13:00:56 +0000 (13:00 +0000)] 
Merge "add postgresql distinct_on  (patch 4)" into main

3 months agoMerge "expand paren rules for default rendering, sqlite/mysql" into main
Michael Bayer [Tue, 18 Mar 2025 12:17:26 +0000 (12:17 +0000)] 
Merge "expand paren rules for default rendering, sqlite/mysql" into main

3 months agoMerge "ensure SQL expressions w/o bool pass through to correct typing error" into...
Michael Bayer [Tue, 18 Mar 2025 01:50:41 +0000 (01:50 +0000)] 
Merge "ensure SQL expressions w/o bool pass through to correct typing error" into main

3 months agoensure SQL expressions w/o bool pass through to correct typing error
Mike Bayer [Mon, 17 Mar 2025 20:46:12 +0000 (16:46 -0400)] 
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

3 months agoMerge "Support column list for foreign key ON DELETE SET actions on PostgreSQL" into...
Michael Bayer [Mon, 17 Mar 2025 21:30:45 +0000 (21:30 +0000)] 
Merge "Support column list for foreign key ON DELETE SET actions on PostgreSQL" into main

3 months agoMerge "remove non_primary parameter" into main
Michael Bayer [Mon, 17 Mar 2025 21:18:49 +0000 (21:18 +0000)] 
Merge "remove non_primary parameter" into main

3 months agofix rst target for Insert
Federico Caselli [Mon, 17 Mar 2025 20:33:31 +0000 (21:33 +0100)] 
fix rst target for Insert

Change-Id: Iee0b8e90223722c40b25c309c47fd6175680ca0e

3 months agoadd postgresql distinct_on (patch 4)
Mike Bayer [Tue, 25 Feb 2025 15:11:29 +0000 (10:11 -0500)] 
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

3 months agoexpand paren rules for default rendering, sqlite/mysql
Mike Bayer [Wed, 12 Mar 2025 20:25:48 +0000 (16:25 -0400)] 
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

3 months agoSupport column list for foreign key ON DELETE SET actions on PostgreSQL
Denis Laxalde [Thu, 13 Mar 2025 12:43:53 +0000 (08:43 -0400)] 
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: d0394db7066ba8a8eaf3d3972d779f3e170e9406

Change-Id: I036a559ae4a8efafe9ba64d776a840bd785a7397

3 months agoMerge "miscellaneous to type dialects" into main
Michael Bayer [Mon, 17 Mar 2025 17:35:20 +0000 (17:35 +0000)] 
Merge "miscellaneous to type dialects" into main

3 months agoMerge "Removes old version added and change notes" into main
Michael Bayer [Mon, 17 Mar 2025 17:31:19 +0000 (17:31 +0000)] 
Merge "Removes old version added and change notes" into main

3 months agoMerge "Add type annotations to `postgresql.array`" into main
Michael Bayer [Mon, 17 Mar 2025 17:29:31 +0000 (17:29 +0000)] 
Merge "Add type annotations to `postgresql.array`" into main

3 months agoremove non_primary parameter
Mike Bayer [Mon, 17 Mar 2025 12:53:00 +0000 (08:53 -0400)] 
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

3 months agoRemoves old version added and change notes
Federico Caselli [Sun, 16 Mar 2025 20:51:00 +0000 (21:51 +0100)] 
Removes old version added and change notes

Removes documentation notes for changes and addition prior to 1.3
included.

Change-Id: Ibabb5222ccafa0c27c8ec40e31b149707d9c8aa3

3 months agoAdd type annotations to `postgresql.array`
Denis Laxalde [Fri, 14 Mar 2025 21:01:50 +0000 (17:01 -0400)] 
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 0bf7e02afbec557eb3a5607db407f27deb7aac77 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: 78eea29f1de850afda036502974521969629de7e

Change-Id: I5d35d15ec8ba4d58eeb9bf00abb710e2e585731f

3 months agomiscellaneous to type dialects
Pablo Estevez [Sat, 8 Feb 2025 15:46:24 +0000 (10:46 -0500)] 
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: 514fe4751c7b1ceefffed2a4ef9c8df339bd9c25

Change-Id: I29314045b2c7eb5428f8d6fec8911c4b6d5ae73e

3 months agoanonymize CRUD params if visiting_cte is present
Mike Bayer [Fri, 14 Mar 2025 14:33:22 +0000 (10:33 -0400)] 
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

3 months agoMerge "re-support mysql-connector python" into main
Michael Bayer [Fri, 14 Mar 2025 12:58:23 +0000 (12:58 +0000)] 
Merge "re-support mysql-connector python" into main

3 months agoMerge "callcount updates" into main
Michael Bayer [Thu, 13 Mar 2025 15:28:25 +0000 (15:28 +0000)] 
Merge "callcount updates" into main

3 months agoMerge "Complement type annotations for ARRAY" into main
Michael Bayer [Thu, 13 Mar 2025 15:27:25 +0000 (15:27 +0000)] 
Merge "Complement type annotations for ARRAY" into main

3 months agocallcount updates
Mike Bayer [Thu, 13 Mar 2025 14:26:50 +0000 (10:26 -0400)] 
callcount updates

not clear why this isn't happening on all py312s but this adjust
profiles for some memory changes that have occurred as of
88b77c8b19523e15d3595b0a58 - just the merge change, not the actual
code change for whatever reason.  very strange

Change-Id: I67849259ea29e5bfb1527036e0d9f63071ec4d4d

3 months agocherry-pick changelog update for 2.0.40
Mike Bayer [Tue, 11 Mar 2025 18:27:27 +0000 (14:27 -0400)] 
cherry-pick changelog update for 2.0.40

3 months agocherry-pick changelog from 2.0.39
Mike Bayer [Tue, 11 Mar 2025 18:27:27 +0000 (14:27 -0400)] 
cherry-pick changelog from 2.0.39

3 months agoMerge "Ensure PostgreSQL network address types are not cast as VARCHAR" into main
Michael Bayer [Tue, 11 Mar 2025 18:07:05 +0000 (18:07 +0000)] 
Merge "Ensure PostgreSQL network address types are not cast as VARCHAR" into main

3 months agoEnsure PostgreSQL network address types are not cast as VARCHAR
Denis Laxalde [Tue, 11 Mar 2025 13:27:13 +0000 (09:27 -0400)] 
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: 029fda7f2d182af71ebc48aef191aa9114927f28

Change-Id: Id4a502ebc119775567cacddbabef2ce9715c1a9f

3 months agoconsolidate kwargs for "FOR UPDATE OF"
Mike Bayer [Tue, 11 Mar 2025 12:33:30 +0000 (08:33 -0400)] 
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

3 months agore-support mysql-connector python
Mike Bayer [Sun, 23 Feb 2025 16:20:18 +0000 (11:20 -0500)] 
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

4 months agoMerge "restate all upsert in terms of statement extensions (patch 3)" into main
Michael Bayer [Fri, 7 Mar 2025 15:09:00 +0000 (15:09 +0000)] 
Merge "restate all upsert in terms of statement extensions (patch 3)" into main

4 months agoMerge "Improve identity column reflection" into main
Michael Bayer [Fri, 7 Mar 2025 14:20:45 +0000 (14:20 +0000)] 
Merge "Improve identity column reflection" into main

4 months agoImprove identity column reflection
Federico Caselli [Mon, 3 Mar 2025 22:35:48 +0000 (23:35 +0100)] 
Improve identity column reflection

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.

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
:meth:`_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.

Fixes: #11751
Change-Id: I8e69de51601dca3257186e38c6f699fbfd9014c6

4 months agoMerge "group together with_polymorphic for single inh criteria" into main
Michael Bayer [Thu, 6 Mar 2025 18:35:06 +0000 (18:35 +0000)] 
Merge "group together with_polymorphic for single inh criteria" into main

4 months agorestate all upsert in terms of statement extensions (patch 3)
Mike Bayer [Mon, 24 Feb 2025 22:53:40 +0000 (17:53 -0500)] 
restate all upsert in terms of statement extensions (patch 3)

Change-Id: I0595ba8e2bd930e22f4c06d7a813bcd23060cb7a

4 months agoimplement mysql limit() for UPDATE/DELETE DML (patch 2)
Mike Bayer [Mon, 24 Feb 2025 20:10:54 +0000 (15:10 -0500)] 
implement mysql limit() for UPDATE/DELETE DML (patch 2)

Added new construct :func:`_mysql.limit` which can be applied to any
:func:`_sql.update` or :func:`_sql.delete` to provide the LIMIT keyword to
UPDATE and DELETE.  This new construct supersedes the use of the
"mysql_limit" dialect keyword argument.

Change-Id: Ie10c2f273432b0c8881a48f5b287f0566dde6ec3

4 months agoMerge "syntax extensions (patch 1)" into main
Michael Bayer [Thu, 6 Mar 2025 14:55:26 +0000 (14:55 +0000)] 
Merge "syntax extensions (patch 1)" into main

4 months agosyntax extensions (patch 1)
Mike Bayer [Mon, 16 Dec 2024 22:29:22 +0000 (17:29 -0500)] 
syntax extensions (patch 1)

Added the ability to create custom SQL constructs that can define new
clauses within SELECT, INSERT, UPDATE, and DELETE statements without
needing to modify the construction or compilation code of of
:class:`.Select`, :class:`.Insert`, :class:`.Update`, or :class:`.Delete`
directly.  Support for testing these constructs, including caching support,
is present along with an example test suite.  The use case for these
constructs is expected to be third party dialects for NewSQL or other novel
styles of database that introduce new clauses to these statements.   A new
example suite is included which illustrates the ``QUALIFY`` SQL construct
used by several NewSQL databases which includes a cachable implementation
as well as a test suite.

Since these extensions start to make it a bit crowded with how many
kinds of "options" we have on statements, did some naming /
documentation changes with existing constructs on Executable, in
particular to distinguish ExecutableOption from SyntaxExtension.

Fixes: #12195
Change-Id: I4a44ee5bbc3d8b1b640837680c09d25b1b7077af

4 months agoComplement type annotations for ARRAY
Denis Laxalde [Wed, 5 Mar 2025 20:59:39 +0000 (15:59 -0500)] 
Complement type annotations for ARRAY

### Description

This complements the type annotations of the `ARRAY` class, in preparation of #12384.

### Checklist

This pull request is:

- [ ] 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.
- [x] 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.

Related to https://github.com/sqlalchemy/sqlalchemy/issues/6810

Closes: #12386
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12386
Pull-request-sha: c9513ce729fa1116b46b02336d4e2cda3d096fee

Change-Id: If9df4708c8e597eedc79ee3990792fa6c72f1afe