Fixes issue in :meth:`_orm.Session.bulk_save_objects()` where it would write a
wrong identity key when using ``return_defaults=True``.
The wrong identity key could lead to an index error when entities are then pickled.
Mike Bayer [Sat, 27 Apr 2024 04:31:07 +0000 (00:31 -0400)]
ensure intermediary mappers emit subclass IN
Fixed issue in :func:`_orm.selectin_polymorhpic` loader option where the
SELECT emitted would only accommodate for the child-most class among the
result rows that were returned, leading intermediary-class attributes to be
unloaded if there were no concrete instances of that intermediary-class
present in the result. This issue only presented itself for multi-level
inheritance hierarchies.
Add a missing `@overload` to the `__add__` operator.
### Description
The `__add__` function is missing an overload that handles the rest of the cases, similar to the one that `__sub__` has a few lines later in the same file.
This fix is taken from https://github.com/microsoft/pyright/issues/7743
### 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.
Mike Bayer [Thu, 18 Apr 2024 22:17:21 +0000 (18:17 -0400)]
consider propagate_to_loaders at application time
Fixed regression from 1.4 where using :func:`_orm.defaultload` in
conjunction with a non-propagating loader like :func:`_orm.contains_eager`
would nonetheless propagate the :func:`_orm.contains_eager` to a lazy load
operation, causing incorrect queries as this option is only intended to
come from an original load.
Fix typing issue in `MetaData.reflect()` with asyncio.
Fixed typing regression caused by PR :ticket:`11055` in version 2.0.29 that
attempted to add ``ParamSpec`` to the asyncio ``run_sync()`` methods, where
using :meth:`_asyncio.AsyncConnection.run_sync` with
meth:`_schema.MetaData.reflect` would fail on mypy due to a bug.
See https://github.com/python/mypy/issues/17093 for details.
Pull request courtesy of Francisco R. Del Roio
Mike Bayer [Mon, 1 Apr 2024 21:54:22 +0000 (17:54 -0400)]
set up is_from_statement and others for FromStatement
Added new attribute :attr:`_orm.ORMExecuteState.is_from_statement`, to
detect statements of the form ``select().from_statement()``, and also
enhanced ``FromStatement`` to set :attr:`_orm.ORMExecuteState.is_select`,
:attr:`_orm.ORMExecuteState.is_insert`,
:attr:`_orm.ORMExecuteState.is_update`, and
:attr:`_orm.ORMExecuteState.is_delete` according to the element that is
sent to the :meth:`_sql.Select.from_statement` method itself.
Mike Bayer [Thu, 28 Mar 2024 13:59:44 +0000 (09:59 -0400)]
use a full ConnectionCharacteristic for logging_token
Fixed issue in the
:paramref:`_engine.Connection.execution_options.logging_token` option,
where changing the value of ``logging_token`` on a connection that has
already logged messages would not be updated to reflect the new logging
token. This in particular prevented the use of
:meth:`_orm.Session.connection` to change the option on the connection,
since the BEGIN logging message would already have been emitted.
Replaces the pyx files with py files that can be both compiled
by cython or imported as is by python.
This avoids the need of duplicating the code to have a python
only fallback.
The cython files are also reorganized to be in the module they use
instead of all being in the cyextension package, that has been
removed.
The performance is pretty much equal between main and this change.
A detailed comparison is at this link
https://docs.google.com/spreadsheets/d/1jkmGpnCyEcPyy6aRK9alElGjxlNHu44Wxjr4VrD99so/edit?usp=sharing
The PostgreSQL dialect now returns :class:`_postgresql.DOMAIN` instances
when reflecting a column that has a domain as type.
Previously the domain data type was returned instead.
As part of this change, the domain reflection was improved to also
return the collation of the text types.
Mike Bayer [Tue, 19 Mar 2024 17:35:35 +0000 (13:35 -0400)]
subqueryload invokes compile() on _OverrideBinds - do robust replace of bp
Fixed regression from version 2.0.28 caused by the fix for :ticket:`11085`
where the newer method of adjusting post-cache bound parameter values would
interefere with the implementation for the :func:`_orm.subqueryload` loader
option, which has some more legacy patterns in use internally, when
the additional loader criteria feature were used with this loader option.
Mike Bayer [Thu, 9 Nov 2023 15:27:19 +0000 (10:27 -0500)]
use a private return class for the "catch all" relationship
Fixed Declarative issue where typing a relationship using
:class:`_orm.Relationship` rather than :class:`_orm.Mapped` would
inadvertently pull in the "dynamic" relationship loader strategy for that
attribute.
Mike Bayer [Wed, 20 Mar 2024 14:23:41 +0000 (10:23 -0400)]
assign variant mapping on adapt()
Fixed regression from the 1.4 series where the refactor of the
:meth:`_types.TypeEngine.with_variant` method introduced at
:ref:`change_6980` failed to accommodate for the ``.copy()`` method, which
will lose the variant mappings that are set up. This becomes an issue for
the very specific case of a "schema" type, which includes types such as
:class:`.Enum` and :class:`.ARRAY`, when they are then used in the context
of an ORM Declarative mapping with mixins where copying of types comes into
play. The variant mapping is now copied as well.
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.
oleg [Tue, 5 Mar 2024 13:18:36 +0000 (08:18 -0500)]
Inline _get_bind_args method.
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
_get_bind_args is strange method in query module. It is called only in one place. It takes self(but don't use it) and two args with Any type. I think it must be static method with typehints if it will has more use cases in the future. But now removing is more simple solution.
Tomasz Nowacki [Mon, 4 Mar 2024 14:52:02 +0000 (09:52 -0500)]
Fixes: #10933 typing in ColumnExpressionArgument
### Description Fixes: #10933 typing in ColumnExpressionArgument
### 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 [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.