Mike Bayer [Mon, 21 Oct 2024 14:03:01 +0000 (10:03 -0400)]
refine in_() check to use proper duck-typing for __clause_element__
Fixed regression caused by an internal code change in response to recent
Mypy releases that caused the very unusual case of a list of ORM-mapped
attribute expressions passed to :meth:`.ColumnOperators.in_` to no longer
be accepted.
in this commit we had to revisit d8dd28c42e where mypy typing
didn't accept ColumnOperartors. the type here is the _HasClauseElement[_T]
protocol which means we need to use a duck type for a runtime check.
Mike Bayer [Mon, 21 Oct 2024 17:10:54 +0000 (13:10 -0400)]
pin older pip for tox under py37
this is suddenly failing due to a non-py37 syntax in
pip/_vendor/typing_extensions.py. Not clear why the failure has just
started however as there is no new version of pip recently.
Mike Bayer [Tue, 15 Oct 2024 12:20:25 +0000 (08:20 -0400)]
add tests for pickling types inside an expression, some reduce methods
Fixed regression from 1.4 where some datatypes such as those derived from
:class:`.TypeDecorator` could not be pickled when they were part of a
larger SQL expression composition due to internal supporting structures
themselves not being pickleable.
Mike Bayer [Mon, 14 Oct 2024 15:15:21 +0000 (11:15 -0400)]
match ORM mapped cols to PK in interpret_returning_rows
Fixed bug in ORM "update with WHERE clause" feature where an explicit
``.returning()`` would interfere with the "fetch" synchronize strategy due
to an assumption that the ORM mapped class featured the primary key columns
in a specific position within the RETURNING. This has been fixed to use
appropriate ORM column targeting.
the _interpret_returning_rows method looked to be mostly not used as far
as its joined inheritance features, which appear to have never been
used as joined inheritance mappers are skipped.
Federico Caselli [Sun, 13 Oct 2024 16:32:46 +0000 (18:32 +0200)]
Render bind cast in json and jsonb in PG
Render bind cast for ``JSON`` and ``JSONB`` datatype on every dialect.
Previously this was only enabled in a subset of dialects. Fixes: #11994
Change-Id: Ib085deb3e84034dac9e4f4057d32f055d5533e52
(cherry picked from commit b2648e69f2375f7257cbe04b16f663d97795db19)
Mike Bayer [Sun, 13 Oct 2024 14:04:23 +0000 (10:04 -0400)]
consult allow_partial_pks for NULL check in lazyload
Refined the check which the ORM lazy loader uses to detect "this would be
loading by primary key and the primary key is NULL, skip loading" to take
into account the current setting for the
:paramref:`.orm.Mapper.allow_partial_pks` parameter. If this parameter is
False, then a composite PK value that has partial NULL elements should also
be skipped. This can apply to some composite overlapping foreign key
configurations.
Federico Caselli [Sat, 12 Oct 2024 12:58:26 +0000 (14:58 +0200)]
Optimize MySQL foreign key reflection
Improved foreign keys reflection logic in MySQL 8+ to use a better
optimized query. The previous query could be quite slow in databases
with a large number of columns.
Added a better error when trying to map as dataclass a class while also
manually providing the ``__table__`` attribute.
This usage is currently not supported.
Mike Bayer [Thu, 10 Oct 2024 02:05:05 +0000 (22:05 -0400)]
_Binary as generic to LargeBinary
Datatypes that are binary based such as :class:`.VARBINARY` will resolve to
:class:`.LargeBinary` when the :meth:`.TypeEngine.as_generic()` method is
called.
Mike Bayer [Tue, 8 Oct 2024 14:29:34 +0000 (10:29 -0400)]
re-apply right memo for nested ORMJoin when splicing
Fixed regression caused by fixes to joined eager loading in
:ticket:`11449`, where a particular joinedload case could not be asserted
correctly. We now have an example of that case so the assertion has been
repaired to allow for it.
Mike Bayer [Wed, 25 Sep 2024 18:19:02 +0000 (14:19 -0400)]
honor prefetch_cols and postfetch_cols in ORM update w/ WHERE criteria
Continuing from :ticket:`11912`, columns marked with
:paramref:`.mapped_column.onupdate`,
:paramref:`.mapped_column.server_onupdate`, or :class:`.Computed` are now
refreshed in ORM instances when running an ORM enabled UPDATE with WHERE
criteria, even if the statement does not use RETURNING or
populate_existing.
this moves the test we added in #11912 to be in
test_update_delete_where, since this behavior is not related to bulk
statements. For bulk statements, we're building onto the "many rows
fast" use case and we as yet intentionally don't do any "bookkeeping",
which means none of the expiration or any of that. would need to rethink
"bulk update" a bit to get onupdates to refresh.
Mike Bayer [Tue, 8 Oct 2024 18:01:40 +0000 (14:01 -0400)]
correct mis-cherry-picked commit for #11449 in 2.0.31
The main review for #11449 at Ie8f0e8d9bb7958baac33c7c2231e4afae15cf5b1
had three revisions but the cherry pick to 2.0 somehow missed the
second two cherry picks. it's not clear if this was intentional.
however, as we need to continue on with correcting this behavior
it seems like we really should have the full "main" behavior in
the release.
Mike Bayer [Sun, 22 Sep 2024 15:34:48 +0000 (11:34 -0400)]
propagate populate_existing for ORM bulk update
Similar to #9742
Fixed bug in ORM bulk update/delete where using RETURNING with bulk
update/delete in combination with populate existing would fail to
accommodate the populate_existing option.
MAINT: pytest doesn't have any more python 3.12 deprecations
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
<!-- Describe your changes in detail -->
I believe this workaround is not needed any more, pytest doesn't have any more python deprecations. (Arguably neither 3.13)
### 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] Tweek to the (testing) infrastructure
- New category as I didn't think this PR fit in any of the 3 options offered.
- [ ] 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.
Merge url query args to opts in mariadbconnector like mysqldb
Fixed issue in mariadbconnector dialect where query string arguments that
weren't checked integer or boolean arguments would be ignored, such as
string arguments like ``unix_socket``, etc. As part of this change, the
argument parsing for particular elements such as ``client_flags``,
``compress``, ``local_infile`` has been made more consistent across all
MySQL / MariaDB dialect which accept each argument. Pull request courtesy
Tobias Alex-Petersen.
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
<!-- Describe your changes in detail -->
I'm chasing some loose datetime.datetime.utcnow() deprecation warning in some test suites, and one of these was seemingly coming from sqlalchemy. It wasn't, but nevertheless these minor cleanup changes may still be found useful.
### 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
Mike Bayer [Mon, 9 Sep 2024 13:21:20 +0000 (09:21 -0400)]
deprecate joinedload, subqueryload with DML; use correct statement
An ORM exception is raised if :func:`_orm.joinedload` or
:func:`_orm.subqueryload` are used as a top level option against a
statement that is not a SELECT statement, such as with an
``insert().returning()``. There are no JOINs in INSERT statements nor is
there a "subquery" that can be repurposed for subquery eager loading, and
for UPDATE/DELETE joinedload does not support these either, so it is never
appropriate for this use to pass silently.
Fixed issue where using eager loaders such as :func:`_orm.selectinload`
with additional criteria in combination with ORM DML such as
:func:`_sql.insert` with RETURNING would not correctly set up internal
contexts required for caching to work correctly, leading to incorrect
results.
Mike Bayer [Sat, 7 Sep 2024 21:41:16 +0000 (17:41 -0400)]
test for Concatenable in ORM evaluator for concat_op
Fixed issue in ORM evaluator where two datatypes being evaluated with the
SQL concatenator operator would not be checked for
:class:`.UnevaluatableError` based on their datatype; this missed the case
of :class:`_postgresql.JSONB` values being used in a concatenate operation
which is supported by PostgreSQL as well as how SQLAlchemy renders the SQL
for this operation, but does not work at the Python level. By implementing
:class:`.UnevaluatableError` for this combination, ORM update statements
will now fall back to "expire" when a concatenated JSON value used in a SET
clause is to be synchronized to a Python object.
Mike Bayer [Thu, 5 Sep 2024 17:21:17 +0000 (13:21 -0400)]
revert SQLite CHECK constraint changes and add new tests
The changes made for SQLite CHECK constraint reflection in versions 2.0.33
and 2.0.34 , :ticket:`11832` and :ticket:`11677`, have now been fully
reverted, as users continued to identify existing use cases that stopped
working after this change. For the moment, because SQLite does not
provide any consistent way of delivering information about CHECK
constraints, SQLAlchemy is limited in what CHECK constraint syntaxes can be
reflected, including that a CHECK constraint must be stated all on a
single, independent line (or inline on a column definition) without
newlines, tabs in the constraint definition or unusual characters in the
constraint name. Overall, reflection for SQLite is tailored towards being
able to reflect CREATE TABLE statements that were originally created by
SQLAlchemy DDL constructs. Long term work on a DDL parser that does not
rely upon regular expressions may eventually improve upon this situation.
A wide range of additional cross-dialect CHECK constraint reflection tests
have been added as it was also a bug that these changes did not trip any
existing tests.
Mike Bayer [Wed, 4 Sep 2024 12:45:52 +0000 (08:45 -0400)]
Fix regular expression for `SQLiteDialect.get_check_constraints`
Fixed regression in SQLite reflection caused by :ticket:`11677` which
interfered with reflection for CHECK constraints that were followed
by other kinds of constraints within the same table definition. Pull
request courtesy Harutaka Kawamura.
Mike Bayer [Wed, 4 Sep 2024 03:08:21 +0000 (23:08 -0400)]
use proper functions to get typing origin, args
Fixed regression caused by issue :ticket:`11814` which broke support for
certain flavors of :pep:`593` ``Annotated`` in the type_annotation_map when
builtin types such as ``list``, ``dict`` were used without an element type.
While this is an incomplete style of typing, these types nonetheless
previously would be located in the type_annotation_map correctly.
Mike Bayer [Mon, 2 Sep 2024 15:22:36 +0000 (11:22 -0400)]
add "The server failed to resume the transaction" to pymssql
Added error "The server failed to resume the transaction" to the list of
error strings for the pymssql driver in determining a disconnect scenario,
as observed by one user using pymssql under otherwise unknown conditions as
leaving an unusable connection in the connection pool which fails to ping
cleanly.
Mike Bayer [Mon, 2 Sep 2024 14:37:29 +0000 (10:37 -0400)]
dont erase transaction if rollback/commit failed outside of asyncpg
Fixed critical issue in the asyncpg driver where a rollback or commit that
fails specifically for the ``MissingGreenlet`` condition or any other error
that is not raised by asyncpg itself would discard the asyncpg transaction
in any case, even though the transaction were still idle, leaving to a
server side condition with an idle transaction that then goes back into the
connection pool. The flags for "transaction closed" are now not reset for
errors that are raised outside of asyncpg itself. When asyncpg itself
raises an error for ``.commit()`` or ``.rollback()``, asyncpg does then
discard of this transaction.
The pin for ``setuptools<69.3`` in ``pyproject.toml`` has been
removed. This pin was to prevent a sudden change to :pep:`625` in
setuptools from taking place which changes the file name of SQLAlchemy's
source distribution on pypi to be an all lower case name, which is very
likely to cause problems with various build environments that expected a
particular naming style. However, the presence of this pin is now holding
back environments that otherwise want to use a newer setuptools, so we've
decided to move forward with this change, with the assumption that build
environments will have largely accommodated the setuptools change by
now.
Mike Bayer [Mon, 2 Sep 2024 15:18:35 +0000 (11:18 -0400)]
add asyncio.CancelledError to terminate conditions
Revising the asyncpg ``terminate()`` fix first made in :ticket:`10717`
which improved the resiliency of this call under all circumstances, adding
``asyncio.CancelledError`` to the list of exceptions that are intercepted
as failing for a graceful ``.close()`` which will then proceed to call
``.terminate()``.
Mike Bayer [Sat, 31 Aug 2024 16:56:00 +0000 (12:56 -0400)]
re-process args for builtin generic types
Improvements to the ORM annotated declarative type map lookup dealing with
composed types such as ``dict[str, Any]`` linking to JSON (or others) with
or without "future annotations" mode.
There's apparently a big incompatiblity in types from typing vs.
Python builtins in the way they genericize. The typing library makes
it very difficult to distinguish between the two sets of types. This
patch is a bit slash and burn to work around all this. These should
likely be reported as bugs in the Python standard library if they
aren't already.
Mike Bayer [Thu, 29 Aug 2024 14:04:47 +0000 (10:04 -0400)]
pass to_metadata argument to Enum.copy()
Fixed bug where the ``metadata`` element of an ``Enum`` datatype would not
be transferred to the new :class:`.MetaData` object when the type had been
copied via a :meth:`.Table.to_metadata` operation, leading to inconsistent
behaviors within create/drop sequences.
John A Stevenson [Mon, 26 Aug 2024 15:05:38 +0000 (11:05 -0400)]
Update SQLite UNIQUE inline constraint parsing to handle tabs
Improvements to the regex used by the SQLite dialect to reflect the name
and contents of a UNIQUE constraint that is defined inline within a column
definition inside of a SQLite CREATE TABLE statement, accommodating for tab
characters present within the column / constraint line. Pull request
courtesy John A Stevenson.