Mike Bayer [Wed, 12 Jun 2024 16:42:29 +0000 (12:42 -0400)]
open up async greenlet for third parties
Modified the internal representation used for adapting asyncio calls to
greenlets to allow for duck-typed compatibility with third party libraries
that implement SQLAlchemy's "greenlet-to-asyncio" pattern directly.
Running code within a greenlet that features the attribute
``__sqlalchemy_greenlet_provider__ = True`` will allow calls to
:func:`sqlalchemy.util.await_only` directly.
Mike Bayer [Tue, 11 Jun 2024 13:16:26 +0000 (09:16 -0400)]
loosen up hash_limit test
hash_limit_string works by doing a modulus of a hash value so that
the range of possible numbers is 0-N. however, there's a chance
we might not populate every 0-N value in unusual cases on CI,
even after iterating 500 times apparently. Loosen the change by making
sure we got at least N/2 unique hash messages but not greater
than N.
Mike Bayer [Tue, 11 Jun 2024 02:59:49 +0000 (22:59 -0400)]
include HasCTE traversal elements in TextualSelect
Fixed caching issue where using the :meth:`.TextualSelect.add_cte` method
of the :class:`.TextualSelect` construct would not set a correct cache key
which distinguished between different CTE expressions.
Mike Bayer [Tue, 4 Jun 2024 14:56:26 +0000 (10:56 -0400)]
add additional contextual path info when splicing eager joins
Fixed very old issue involving the :paramref:`_orm.joinedload.innerjoin`
parameter where making use of this parameter mixed into a query that also
included joined eager loads along a self-referential or other cyclical
relationship, along with complicating factors like inner joins added for
secondary tables and such, would have the chance of splicing a particular
inner join to the wrong part of the query. Additional state has been added
to the internal method that does this splice to make a better decision as
to where splicing should proceed.
Mike Bayer [Mon, 3 Jun 2024 18:50:25 +0000 (14:50 -0400)]
expand entity_isa to include simple "isa" in poly case
Fixed issue where the :func:`_orm.selectinload` and
:func:`_orm.subqueryload` loader options would fail to take effect when
made against an inherited subclass that itself included a subclass-specific
:paramref:`_orm.Mapper.with_polymorphic` setting.
Federico Caselli [Wed, 29 May 2024 19:39:08 +0000 (21:39 +0200)]
Make `FunctionFilter.filter` generative
Fixed bug in :meth:`_sql.FunctionFilter.filter` that would mutate
the existing function in-place. It now behaves like the rest of the
SQLAlchemy API, returning a new instance instead of mutating the
original one.
Mike Bayer [Sun, 26 May 2024 15:34:27 +0000 (11:34 -0400)]
skip dunders for langhelper symbol redefine; update tox
Set up full Python 3.13 support to the extent currently possible, repairing
issues within internal language helpers as well as the serializer extension
module.
update tox for what will be a regular condition: greenlet is
not available (and possibly other things like pymssql):
1. dont use "sqlalchemy[asyncio]" in pyproejct.toml as an extra; this
goes out to pypi and ignores the local file
2. add py{3,38,39,...} qualifiers for asyncio deps in tox.ini. After
many attempts I seem to have something that's fairly non-repetetive
though I'd still prefer a single variable for this, somehow
Mike Bayer [Fri, 24 May 2024 14:58:02 +0000 (10:58 -0400)]
Add test for issue 11412
Issue #10365 was found to also fix an issue where
single-inheritance criteria would not be correctly applied to a
subclass entity that only appeared in the ``select_from()`` list.
Semyon Pupkov [Sat, 11 May 2024 12:41:06 +0000 (08:41 -0400)]
Optimize has_intersection func
<!-- Provide a general summary of your proposed changes in the Title field above -->
Optimize `has_intersection` function. It uses in few places, but even so it might be optimized. New version:
1. Does not allocate new set
2. A bit of performance speedup
```
from sqlalchemy import util
import timeit
import functools
a = {1, 2, 3}
b = [2, 3, 4]
t1 = timeit.Timer(functools.partial(util.has_intersection, a, b))
t2 = timeit.Timer(functools.partial(util.has_intersection2, a, b))
### 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:
- [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 [Tue, 7 May 2024 22:03:51 +0000 (18:03 -0400)]
setup JoinedDispatch to support pickling
Fixed issue where a :class:`.MetaData` collection would not be
serializable, if an :class:`.Enum` or :class:`.Boolean` datatype were
present which had been adapted. This specific scenario in turn could occur
when using the :class:`.Enum` or :class:`.Boolean` within ORM Annotated
Declarative form where type objects frequently get copied.
Mike Bayer [Sat, 4 May 2024 14:38:48 +0000 (10:38 -0400)]
revise approach for bundle deduping
Revise the approach from 7d6d7ef73 to make a special case for
Bundle-targeted columns entirely, and don't involve the
_label_convention() callable. Add tests for select() with
tablename labeling convention.
Mark Elliot [Mon, 29 Apr 2024 21:50:10 +0000 (17:50 -0400)]
Add overload for ColumnCollection.get(col, default)
### Description
Fixes #11328 by adding an overload to ColumnCollection when a non-None default is provided.
### Checklist
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.
Fixed issue in ORM Annotated Declarative where typing issue where literals
defined using :pep:`695` type aliases would not work with inference of
:class:`.Enum` datatypes. Pull request courtesy of Alc-Alc.
Mike Bayer [Thu, 2 May 2024 15:45:31 +0000 (11:45 -0400)]
disable col deduping inside of Bundle
Fixed issue where attribute key names in :class:`_orm.Bundle` would not be
correct when using ORM enabled :class:`_sql.select` vs.
:class:`_orm.Query`, when the statement contained duplicate column names.
Fixed issue in typing for :class:`_orm.Bundle` where creating a nested
:class:`_orm.Bundle` structure were not allowed.
Mike Bayer [Tue, 30 Apr 2024 19:41:04 +0000 (15:41 -0400)]
ensure result_map objects collection is non-empty
Fixed issue in cursor handling which affected handling of duplicate
:class:`_sql.Column` or similar objcts in the columns clause of
:func:`_sql.select`, both in combination with arbitary :func:`_sql.text()`
clauses in the SELECT list, as well as when attempting to retrieve
:meth:`_engine.Result.mappings` for the object, which would lead to an
internal error.
Ignore all dunders when checking attributes in `sqlalchemy.util.langhelpers.TypingOnly`
Fixed an internal class that was testing for unexpected attributes to work
correctly under upcoming Python 3.13. Pull request courtesy Edgar
Ramírez-Mondragón.
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 [Sun, 28 Apr 2024 17:39:08 +0000 (13:39 -0400)]
only consider column / relationship attrs for subclass IN
Fixed issue in :func:`_orm.selectin_polymorhpic` loader option where
attributes defined with :func:`_orm.composite` on a superclass would cause
an internal exception on load.
Define the prop for :class:`.PropRegistry` as a
:class:`.StrategizedProperty`; we dont make path registries for
descriptor props like synonyms, composites, etc.
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.
Mike Bayer [Sat, 23 Mar 2024 20:59:40 +0000 (16:59 -0400)]
typing fix
the most recent greenlet/asyncio commit introduced a typing error
that only comes up under python3.10 due to the non-presence of
asyncio.Runner in that version. do an intricate dance here along with
another python-version-specific thing observed around the greenlet
import.
Mike Bayer [Sat, 23 Mar 2024 17:02:46 +0000 (13:02 -0400)]
use asyncio.Runner for tests
Backported to SQLAlchemy 2.0 an improvement to the test suite with regards
to how asyncio related tests are run, now using the newer Python 3.11
``asyncio.Runner`` or a backported equivalent, rather than relying on the
previous implementation based on ``asyncio.get_running_loop()``. This
should hopefully prevent issues with large suite runs on CPU loaded
hardware where the event loop seems to become corrupted, leading to
cascading failures.
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.