Mike Bayer [Fri, 15 Mar 2024 14:51:02 +0000 (10:51 -0400)]
remove sentinel_value_resolvers and use pre-bind values
Made a change to the adjustment made in version 2.0.10 for :ticket:`9618`,
which added the behavior of reconciling RETURNING rows from a bulk INSERT
to the parameters that were passed to it. This behavior included a
comparison of already-DB-converted bound parameter values against returned
row values that was not always "symmetrical" for SQL column types such as
UUIDs, depending on specifics of how different DBAPIs receive such values
versus how they return them, necessitating the need for additional
"sentinel value resolver" methods on these column types. Unfortunately
this broke third party column types such as UUID/GUID types in libraries
like SQLModel which did not implement this special method, raising an error
"Can't match sentinel values in result set to parameter sets". Rather than
attempt to further explain and document this implementation detail of the
"insertmanyvalues" feature including a public version of the new
method, the approach is intead revised to no longer need this extra
conversion step, and the logic that does the comparison now works on the
pre-converted bound parameter value compared to the post-result-processed
value, which should always be of a matching datatype. In the unusual case
that a custom SQL column type that also happens to be used in a "sentinel"
column for bulk INSERT is not receiving and returning the same value type,
the "Can't match" error will be raised, however the mitigation is
straightforward in that the same Python datatype should be passed as that
returned.
Sean Bright [Fri, 15 Mar 2024 17:57:28 +0000 (13:57 -0400)]
mysql: Add new reserved words from MySQL 8.3.
Adds the following new keywords from MySQL 8.3:
* `intersect`
* `parallel`
* `qualify`
Sourced from https://dev.mysql.com/doc/refman/8.3/en/keywords.html
Fixes: #11166
<!-- 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
- [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.
Mike Bayer [Wed, 13 Mar 2024 22:23:07 +0000 (18:23 -0400)]
accommodate schema_translate_map in _deliver_insertmanyvalues_batches
Fixed issue in :ref:`engine_insertmanyvalues` feature where using a primary
key column with an "inline execute" default generator such as an explicit
:class:`.Sequence` with an explcit schema name, while at the same time
using the
:paramref:`_engine.Connection.execution_options.schema_translate_map`
feature would fail to render the sequence or the parameters properly,
leading to errors.
Ethan Langevin [Mon, 11 Mar 2024 11:41:58 +0000 (07:41 -0400)]
Make instrumented attribute covariant as well
<!-- Provide a general summary of your proposed changes in the Title field above -->
Allows mapped relationships to use covariant types which makes it possible to define methods that operate on relationships in a typesafe way
### Description
See: https://github.com/sqlalchemy/sqlalchemy/issues/11112 for a more in depth explanation.
Just changed the type parameter in `InstrumentedAttribute` from `_T` to `_T_co`.
### 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.
Jens Troeger [Mon, 11 Mar 2024 21:11:45 +0000 (17:11 -0400)]
add a docs cross-reference between adding columns & relationships to existing table mappings
For context see discussion https://github.com/sqlalchemy/sqlalchemy/discussions/11124. This change adds the requested cross-reference to the documentation.
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.
Fixed typing issue allowing asyncio ``run_sync()`` methods to correctly
type the parameters according to the callable that was passed, making use
of :pep:`612` ``ParamSpec`` variables. Pull request courtesy Francisco R.
Del Roio.
Mike Bayer [Sat, 9 Mar 2024 17:47:01 +0000 (12:47 -0500)]
add extra pep695 conversion step
Added support for the :pep:`695` ``TypeAliasType`` construct as well as the
python 3.12 native ``type`` keyword to work with ORM Annotated Declarative
form when using these constructs to link to a :pep:`593` ``Annotated``
container, allowing the resolution of the ``Annotated`` to proceed when
these constructs are used in a :class:`_orm.Mapped` typing container.
Mike Bayer [Mon, 4 Mar 2024 14:12:34 +0000 (09:12 -0500)]
accommodate False conditions for unique / index merge
Fixed issue in ORM annotated declarative where using
:func:`_orm.mapped_column()` with an :paramref:`_orm.mapped_column.index`
or :paramref:`_orm.mapped_column.unique` setting of False would be
overridden by an incoming ``Annotated`` element that featured that
parameter set to ``True``, even though the immediate
:func:`_orm.mapped_column()` element is more specific and should take
precedence. The logic to reconcile the booleans has been enhanced to
accommodate a local value of ``False`` as still taking precedence over an
incoming ``True`` value from the annotated element.
Mike Bayer [Mon, 4 Mar 2024 04:03:14 +0000 (23:03 -0500)]
support pytest 8.1
This is a bump in the tox.ini file. it's possible we
don't need to change anything else as we had help from the pytest
people a few years back to make sure our API use was fairly modern.
Alembic is having problems that appear to be separate.
Mike Bayer [Sat, 2 Mar 2024 05:28:26 +0000 (00:28 -0500)]
adjust bound parameters within cache key only, dont deep copy
Adjusted the fix made in :ticket:`10570`, released in 2.0.23, where new
logic was added to reconcile possibly changing bound parameter values
across cache key generations used within the :func:`_orm.with_expression`
construct. The new logic changes the approach by which the new bound
parameter values are associated with the statement, avoiding the need to
deep-copy the statement which can result in a significant performance
penalty for very deep / complex SQL constructs. The new approach no longer
requires this deep-copy step.
Add support for preserve_rowcount execution_option
Added new core execution option
paramref:`_engine.Connection.execution_options.preserve_rowcount`
to unconditionally save the ``rowcount`` attribute from the cursor in the
class:`_engine.Result` returned from an execution, regardless of the
statement being executed.
When this option is provided the correct value is also set when
an INSERT makes use of the "insertmanyvalues" mode, that may use
more than one actualy cursor execution.
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 [Thu, 15 Feb 2024 02:10:20 +0000 (21:10 -0500)]
raise for asyncio-incompatible pool classes
An error is raised if a :class:`.QueuePool` or other non-asyncio pool class
is passed to :func:`_asyncio.create_async_engine`. This engine only
accepts asyncio-compatible pool classes including
:class:`.AsyncAdaptedQueuePool`. Other pool classes such as
:class:`.NullPool` are compatible with both synchronous and asynchronous
engines as they do not perform any locking.
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.
References: https://github.com/sqlalchemy/sqlalchemy/discussions/10923
Change-Id: Ie9260e4076bc82da0ef6dc11349a85beb0223a33
(cherry picked from commit f7b40c0102c33faf350917f5b98c61d4c6fbec90)
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.
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.
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.
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.