Modified the MariaDB dialect so that when using the :class:`_sqltypes.Uuid`
datatype with MariaDB >= 10.7, leaving the
:paramref:`_sqltypes.Uuid.native_uuid` parameter at its default of True,
the native ``UUID`` datatype will be rendered in DDL and used for database
communication, rather than ``CHAR(32)`` (the non-native UUID type) as was
the case previously. This is a behavioral change since 2.0, where the
generic :class:`_sqltypes.Uuid` datatype delivered ``CHAR(32)`` for all
MySQL and MariaDB variants. Support for all major DBAPIs is implemented
including support for less common "insertmanyvalues" scenarios where UUID
values are generated in different ways for primary keys. Thanks much to
Volodymyr Kochetkov for delivering the PR.
To support this fully without hacks, the mariadb dialect now supports
driver-specific mariadb dialects as well, where we add one here for the
mysqlconnector DBAPI that doesn't accept Python UUID objects, whereas
all the other ones do.
Zhong Zheng [Fri, 16 Feb 2024 17:20:59 +0000 (12:20 -0500)]
Fix mysql dialect text docstring, length is interpreted as byte size
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
The `Text` and its variant types in MySQL are bytes size limited, not character length, so fixing the doctoring where the upper limit uses the `characters` as the unit instead of `bytes`
<img width="878" alt="Screenshot 2024-02-15 at 17 27 59" src="https://github.com/sqlalchemy/sqlalchemy/assets/5219229/29731769-f57e-46f9-858b-46feda0ae83c">
### 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.
Mike Bayer [Wed, 14 Feb 2024 14:29:19 +0000 (09:29 -0500)]
ensure secondary cols not excluded from adaption
Fixed regression caused by :ticket:`9779` where using the "secondary" table
in a relationship ``and_()`` expression would fail to be aliased to match
how the "secondary" table normally renders within a
:meth:`_sql.Select.join` expression, leading to an invalid query.
Mike Bayer [Tue, 13 Feb 2024 13:45:53 +0000 (08:45 -0500)]
use correct exception for terminate catch + test
Fixed regression caused by just-released fix for :ticket:`10863` where an
invalid exception class were added to the "except" block, which does not
get exercised unless such a catch actually happens. A mock-style test has
been added to ensure this catch is exercised in unit tests.
Mike Bayer [Thu, 8 Feb 2024 13:45:22 +0000 (08:45 -0500)]
handle case where neither side has a cache key
Fixed issue where an assertion within the implementation for
:func:`_orm.with_expression` would raise if a SQL expression that was not
cacheable were used; this was a 2.0 regression since 1.4.
Jim Bosch [Tue, 14 Nov 2023 21:19:31 +0000 (16:19 -0500)]
Fix typing generics in PostgreSQL range types.
Correctly type PostgreSQL RANGE and MULTIRANGE types as ``Range[T]``
and ``Sequence[Range[T]]``.
Introduced utility sequence ``MultiRange`` to allow better
interoperability of MULTIRANGE types.
Mike Bayer [Tue, 6 Feb 2024 23:11:32 +0000 (18:11 -0500)]
restore uuid_data_type as closed at top level
the supports_native_uuid attribute does NOT indicate
the UUID datatype being present, only that Uuid(native_uuid=True)
would be able to produce something. On SQL Server it produces
UNIQUEIDENTIFIER. The current use for this requirement is
that of testing the uppercase UUID type that has to match
that exactly.
Mike Bayer [Thu, 18 Jan 2024 17:47:02 +0000 (12:47 -0500)]
include cls locals in annotation evaluate
Fixed issue where it was not possible to use a type (such as an enum)
within a :class:`_orm.Mapped` container type if that type were declared
locally within the class body. The scope of locals used for the eval now
includes that of the class body itself. In addition, the expression within
:class:`_orm.Mapped` may also refer to the class name itself, if used as a
string or with future annotations mode.
Mike Bayer [Mon, 5 Feb 2024 17:02:19 +0000 (12:02 -0500)]
add additional IMV UUID tests, fix pymssql case
Fixed an issue regarding the use of the :class:`.Uuid` datatype with the
:paramref:`.Uuid.as_uuid` parameter set to False, when using the pymssql
dialect. ORM-optimized INSERT statements (e.g. the "insertmanyvalues"
feature) would not correctly align primary key UUID values for bulk INSERT
statements, resulting in errors.
This change also adds a small degree of generalization to the
Uuid datatype by adding the native/non-native compilation conditional
to the base compiler.
Patch is originally part of Ib920871102b9b64f2cba9697f5cb72b6263e4ed8
which is implementing native UUID for mariadb in 2.1 only.
Mike Bayer [Mon, 5 Feb 2024 21:06:28 +0000 (16:06 -0500)]
run postfetch_post_update for version_id_col even if delete
Fixed issue where using :meth:`_orm.Session.delete` along with the
:paramref:`_orm.Mapper.version_id_col` feature would fail to use the
correct version identifier in the case that an additional UPDATE were
emitted against the target object as a result of the use of
:paramref:`_orm.relationship.post_update` on the object. The issue is
similar to :ticket:`10800` just fixed in version 2.0.25 for the case of
updates alone.
Mike Bayer [Fri, 26 Jan 2024 14:17:31 +0000 (09:17 -0500)]
re-establish section on why __init__ not called on load
this section got lost, leaving the FAQ to point to an
empty document. Rewrite a new section introducing that
__init__ is not called on load, illustrate strategies.
I am not that happy with *where* this doc is, as this is
supposed to be "mapping styles" high level introductory
type stuff, but there's nowhere else for it.
Mike Bayer [Tue, 23 Jan 2024 19:06:01 +0000 (14:06 -0500)]
suffix index names with "_history" just like tables
Fixed regression in history_meta example where the use of
:meth:`_schema.MetaData.to_metadata` to make a copy of the history table
would also copy indexes (which is a good thing), but causing naming
conflicts indexes regardless of naming scheme used for those indexes. A
"_history" suffix is now added to these indexes in the same way as is
achieved for the table name.
Fixed issue where NULL/NOT NULL would not be properly reflected from a
MySQL column that also specified the VIRTUAL or STORED directives. Pull
request courtesy Georg Wicke-Arndt.
Yurii Karabas [Wed, 17 Jan 2024 17:08:05 +0000 (12:08 -0500)]
Add PEP 646 integration
The :class:`.Row` object now no longer makes use of an intermediary
``Tuple`` in order to represent its individual element types; instead,
the individual element types are present directly, via new :pep:`646`
integration, now available in more recent versions of Mypy. Mypy
1.7 or greater is now required for statements, results and rows
to be correctly typed. Pull request courtesy Yurii Karabas.
Support specifying access method when creating Postgres tables
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
<!-- Describe your changes in detail -->
### 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
- [ ] 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.
Mike Bayer [Thu, 18 Jan 2024 02:15:37 +0000 (21:15 -0500)]
remove loader depth warning, replace with logging message
Replaced the "loader depth is excessively deep" warning with a shorter
message added to the caching badge within SQL logging, for those statements
where the ORM disabled the cache due to a too-deep chain of loader options.
The condition which this warning highlights is difficult to resolve and is
generally just a limitation in the ORM's application of SQL caching. A
future feature may include the ability to tune the threshold where caching
is disabled, but for now the warning will no longer be a nuisance.
Federico Caselli [Fri, 12 Jan 2024 18:17:30 +0000 (19:17 +0100)]
Oracle default arraysize is now set by the driver
Changed the default arraysize of the Oracle dialects so that the value set
by the driver is used, that is 100 at the time of writing for both
cx_oracle and oracledb. Previously the value was set to 50 by default.
Priyanshu Parikh [Sun, 15 Oct 2023 14:34:25 +0000 (10:34 -0400)]
allow callable for relationship.back_populates
The :paramref:`_orm.relationship.back_populates` argument to
:func:`_orm.relationship` may now be passed as a Python callable, which
resolves to either the direct linked ORM attribute, or a string value as
before. ORM attributes are also accepted directly by
:paramref:`_orm.relationship.back_populates`. This change allows type
checkers and IDEs to confirm the argument for
:paramref:`_orm.relationship.back_populates` is valid. Thanks to Priyanshu
Parikh for the help on suggesting and helping to implement this feature.
An attempt was made to do this for ForeignKey as well, however this
is not feasible since there is no "deferred configuration" step
for Table objects; Table objects set each other up on ForeignKey
as they are created, such as setting the type of a column
in a referencing Column when the referenced table is created. We
have no way to know which Table a foreign key intends to represent
when it's a callable whereas when it's a string, we do know, and
we actually make a lot of use of that string to match it to the
target table as that target is created (see _fk_memos). However
the commit keeps a little bit of the cleanup to ForeignKey intact.
Gord Thompson [Sun, 14 Jan 2024 16:49:11 +0000 (09:49 -0700)]
use ensure_closed() for async close, close() for terminate
Fixed issue in asyncio dialects asyncmy and aiomysql, where their
``.close()`` method is apparently not a graceful close. replace with
non-standard ``.ensure_closed()`` method that's awaitable and move
``.close()`` to the so-called "terminate" case.
Martijn Pieters [Tue, 16 Jan 2024 12:03:09 +0000 (07:03 -0500)]
Correct type hint for FunctionElement.table_valued()
### Description
The documentation and the type annotations for `TableValueType()` clearly
state that both strings and column expression arguments are accepted
but the annotation omits `str`, which is the most common use case.
### Checklist
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.
David Evans [Mon, 15 Jan 2024 15:13:53 +0000 (10:13 -0500)]
Fix type of CASE expressions which include NULLs
Fixed issues in :func:`_sql.case` where the logic for determining the
type of the expression could result in :class:`.NullType` if the last
element in the "whens" had no type, or in other cases where the type
could resolve to ``None``. The logic has been updated to scan all
given expressions so that the first non-null type is used, as well as
to always ensure a type is present. Pull request courtesy David Evans.
updates to test suite to use modern fixture patterns by Mike
Mike Bayer [Fri, 12 Jan 2024 14:29:28 +0000 (09:29 -0500)]
add Identity() for remaining examples
Fixed the performance example scripts in examples/performance to mostly
work with the Oracle database, by adding the :class:`.Identity` construct
to all the tables and allowing primary generation to occur on this backend.
A few of the "raw DBAPI" cases still are not compatible with Oracle.
Support reflecting no inherit check constraint in pg.
Added support for reflection of PostgreSQL CHECK constraints marked with
"NO INHERIT", setting the key ``no_inherit=True`` in the reflected data.
Pull request courtesy Ellis Valentiner.
Mike Bayer [Thu, 11 Jan 2024 03:31:59 +0000 (22:31 -0500)]
catch OSError (base of ConnectionError) and asyncpg errors for terminate
Fixed regression in the asyncpg dialect caused by :ticket:`10717` in
release 2.0.24 where the change that now attempts to gracefully close the
asyncpg connection before terminating would not fall back to
``terminate()`` for other potential connection-related exceptions other
than a timeout error, not taking into account cases where the graceful
``.close()`` attempt fails for other reasons such as connection errors.
Mike Bayer [Mon, 8 Jan 2024 14:15:17 +0000 (09:15 -0500)]
DBAPIConnection can be None for checkin event
Fixed the type signature for the :meth:`.PoolEvents.checkin` event to
indicate that the given :class:`.DBAPIConnection` argument may be ``None``
in the case where the connection has been invalidated.
Mike Bayer [Tue, 2 Jan 2024 16:16:13 +0000 (11:16 -0500)]
refactor any_ / all_
Improved compilation of :func:`_sql.any_` / :func:`_sql.all_` in the
context of a negation of boolean comparison, will now render ``NOT (expr)``
rather than reversing the equality operator to not equals, allowing
finer-grained control of negations for these non-typical operators.
Federico Caselli [Thu, 21 Dec 2023 22:41:56 +0000 (23:41 +0100)]
Add oracledb_async driver support
Added support for :ref:`oracledb` in async mode.
The current implementation has some limitation, preventing
the support for :meth:`_asyncio.AsyncConnection.stream`.
Improved support if planned for the 2.1 release of SQLAlchemy.
Mike Bayer [Tue, 2 Jan 2024 16:36:20 +0000 (11:36 -0500)]
force uselist=False for all collection class not present
Fixed issue where ORM Annotated Declarative would mis-interpret the left
hand side of a relationship without any collection specified as
uselist=True if the left type were given as a class and not a string,
without using future-style annotations.
jonathan vanasco [Fri, 24 Sep 2021 21:48:09 +0000 (17:48 -0400)]
add new notes on viewonly section
Updated join_conditions documentation to explain the limits of mutation
tracking on advanced relationships and illustrate potential ways to
remedy the situation.
Instead of simply writing a note, the (functional) code from the original
issue was turned into a tutorial that explains the various approaches.
Mike Bayer [Mon, 1 Jan 2024 21:54:58 +0000 (16:54 -0500)]
ensure correct lock type propagated in pool recreate
Fixed critical issue in asyncio version of the connection pool where
calling :meth:`_asyncio.AsyncEngine.dispose` would produce a new connection
pool that did not fully re-establish the use of asyncio-compatible mutexes,
leading to the use of a plain ``threading.Lock()`` which would then cause
deadlocks in an asyncio context when using concurrency features like
``asyncio.gather()``.
Mike Bayer [Mon, 1 Jan 2024 17:49:10 +0000 (12:49 -0500)]
add a generic argument to _HasClauseElement
Further enhancements to pep-484 typing to allow SQL functions from
:attr:`_sql.func` derived elements to work more effectively with ORM-mapped
attributes.
Mike Bayer [Thu, 28 Dec 2023 21:02:48 +0000 (16:02 -0500)]
pop prefetch values from committed_state when they are available
Fixed issue where when making use of the
:paramref:`_orm.relationship.post_update` feature at the same time as using
a mapper version_id_col could lead to a situation where the second UPDATE
statement emitted by the post-update feature would fail to make use of the
correct version identifier, assuming an UPDATE was already emitted in that
flush which had already bumped the version counter.