diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-06 16:47:00 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-06 17:12:35 -0400 |
| commit | 5ef1b89d865679fa2ca4bb3e3c1892bdd966ad89 (patch) | |
| tree | c0d7d9199e696a1c504dc6c2e9156f3d6369d0a9 /lib/sqlalchemy/sql | |
| parent | d5a22410474f51170f18958a623e4f6c05e6b47e (diff) | |
| download | sqlalchemy-5ef1b89d865679fa2ca4bb3e3c1892bdd966ad89.tar.gz | |
Disable and disallow Result.unique() with yield_per
Fixed critical regression where the :meth:`_orm.Query.yield_per` method in
the ORM would set up the internal :class:`_engine.Result` to yield chunks
at a time, however made use of the new :meth:`_engine.Result.unique` method
which uniques across the entire result. This would lead to lost rows since
the ORM is using ``id(obj)`` as the uniquing function, which leads to
repeated identifiers for new objects as already-seen objects are garbage
collected. 1.3's behavior here was to "unique" across each chunk, which
does not actually produce "uniqued" results when results are yielded in
chunks. As the :meth:`_orm.Query.yield_per` method is already explicitly
disallowed when joined eager loading is in place, which is the primary
rationale for the "uniquing" feature, the "uniquing" feature is now turned
off entirely when :meth:`_orm.Query.yield_per` is used.
This regression only applies to the legacy :class:`_orm.Query` object; when
using :term:`2.0 style` execution, "uniquing" is not automatically applied.
To prevent the issue from arising from explicit use of
:meth:`_engine.Result.unique`, an error is now raised if rows are fetched
from a "uniqued" ORM-level :class:`_engine.Result` if any
:ref:`yield per <orm_queryguide_yield_per>` API is also in use, as the
purpose of ``yield_per`` is to allow for arbitrarily large numbers of rows,
which cannot be uniqued in memory without growing the number of entries to
fit the complete result size.
Fixes: #6206
Change-Id: I3770d1f2e9be44d82c83ca992afb912dcc17af05
Diffstat (limited to 'lib/sqlalchemy/sql')
0 files changed, 0 insertions, 0 deletions
