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.
Mike Bayer [Tue, 19 Sep 2023 12:58:52 +0000 (08:58 -0400)]
Ensure loader criteria used for ORM join with expression condition
Fixed bug where ORM :func:`_orm.with_loader_criteria` would not apply
itself to a :meth:`_sql.Select.join` where the ON clause were given as a
plain SQL comparison, rather than as a relationship target or similar.
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 [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()``.
Yilei Yang [Thu, 21 Dec 2023 07:47:03 +0000 (02:47 -0500)]
Use a copy of `self.contents` in this list comprehension.
Improved a fix first implemented for :ticket:`3208` released in version
0.9.8, where the registry of classes used internally by declarative could
be subject to a race condition in the case where individual mapped classes
are being garbage collected at the same time while new mapped classes are
being constructed, as can happen in some test suite configurations or
dynamic class creation environments. In addition to the weakref check
already added, the list of items being iterated is also copied first to
avoid "list changed while iterating" errors. Pull request courtesy Yilei
Yang.
Mike Bayer [Tue, 17 Oct 2023 22:54:23 +0000 (18:54 -0400)]
revise argument to mysqlclient/pymysql ping
Repaired a new incompatibility in the MySQL "pre-ping" routine where the
``False`` argument passed to ``connection.ping()``, which is intended to
disable an unwanted "automatic reconnect" feature, is being deprecated in
MySQL drivers and backends, and is producing warnings for some versions of
MySQL's native client drivers. It's removed for mysqlclient, whereas for
PyMySQL and drivers based on PyMySQL, the parameter will be deprecated and
removed at some point, so API introspection is used to future proof against
these various stages of removal.
Mike Bayer [Thu, 19 Oct 2023 15:21:26 +0000 (11:21 -0400)]
dont mis-render value from previous loop iteration
Fixed issue where using the same bound parameter more than once with
``literal_execute=True`` in some combinations with other literal rendering
parameters would cause the wrong values to render due to an iteration
issue.
Mike Bayer [Thu, 10 Aug 2023 22:26:45 +0000 (18:26 -0400)]
safe annotate QueryableAttribute inside of join() condition
Fixed fundamental issue which prevented some forms of ORM "annotations"
from taking place for subqueries which made use of :meth:`_sql.Select.join`
against a relationship target. These annotations are used whenever a
subquery is used in special situations such as within
:meth:`_orm.PropComparator.and_` and other ORM-specific scenarios.
Mike Bayer [Wed, 9 Aug 2023 14:17:35 +0000 (10:17 -0400)]
implement custom setstate to work around implicit type/comparator
Fixed issue where unpickling of a :class:`_schema.Column` or other
:class:`_sql.ColumnElement` would fail to restore the correct "comparator"
object, which is used to generate SQL expressions specific to the type
object.
Mike Bayer [Fri, 30 Jun 2023 14:14:55 +0000 (10:14 -0400)]
remove use of SQL expressions in "modifiers" for regexp
Fixed issue where the :meth:`_sql.ColumnOperators.regexp_match`
when using "flags" would not produce a "stable" cache key, that
is, the cache key would keep changing each time causing cache pollution.
The same issue existed for :meth:`_sql.ColumnOperators.regexp_replace`
with both the flags and the actual replacement expression.
The flags are now represented as fixed modifier strings rendered as
safestrings rather than bound parameters, and the replacement
expression is established within the primary portion of the "binary"
element so that it generates an appropriate cache key.
Note that as part of this change, the
:paramref:`_sql.ColumnOperators.regexp_match.flags` and
:paramref:`_sql.ColumnOperators.regexp_replace.flags` have been modified to
render as literal strings only, whereas previously they were rendered as
full SQL expressions, typically bound parameters. These parameters should
always be passed as plain Python strings and not as SQL expression
constructs; it's not expected that SQL expression constructs were used in
practice for this parameter, so this is a backwards-incompatible change.
The change also modifies the internal structure of the expression
generated, for :meth:`_sql.ColumnOperators.regexp_replace` with or without
flags, and for :meth:`_sql.ColumnOperators.regexp_match` with flags. Third
party dialects which may have implemented regexp implementations of their
own (no such dialects could be located in a search, so impact is expected
to be low) would need to adjust the traversal of the structure to
accommodate.
Fixed issue in mostly-internal :class:`.CacheKey` construct where the
``__ne__()`` operator were not properly implemented, leading to nonsensical
results when comparing :class:`.CacheKey` instances to each other.
Mike Bayer [Mon, 3 Jul 2023 12:09:06 +0000 (08:09 -0400)]
adjust py312 fix
- version detection should anticipate pyhex version on 3.12.0.0
- github actions has removed py2.7 totally
- put changelog in correct place / tags
- not sure what to do for py2.7 wheels for 1.4. might have to just go
with there being no py2.7 wheel on pypi
Mike Bayer [Wed, 21 Jun 2023 18:59:21 +0000 (14:59 -0400)]
qualify mypy1.4 update for python 3.9, 3.10 +
in I68084199858e9da901641d6036780437bcf5f2d6 we added a mypy1.4
check to check for new-style type messages. mypy only
does lowercase types on python 3.9 and above, OR syntax on 3.10
and above. qualify these both
Mike Bayer [Sun, 30 Apr 2023 17:56:33 +0000 (13:56 -0400)]
do not allow non-cache-key entity objects in annotations
Fixed critical caching issue where combination of :func:`_orm.aliased()`
:func:`_sql.case` and :func:`_hybrid.hybrid_property` expressions would
cause a cache key mismatch, leading to cache keys that held onto the actual
:func:`_orm.aliased` object while also not matching each other, filling up
the cache.
Mike Bayer [Mon, 17 Apr 2023 14:16:35 +0000 (10:16 -0400)]
dont assume _compile_options are present
Fixed bug where various ORM-specific getters such as
:attr:`.ORMExecuteState.is_column_load`,
:attr:`.ORMExecuteState.is_relationship_load`,
:attr:`.ORMExecuteState.loader_strategy_path` etc. would throw an
``AttributeError`` if the SQL statement itself were a "compound select"
such as a UNION.
Mike Bayer [Sun, 2 Apr 2023 18:24:32 +0000 (14:24 -0400)]
consider aliased mappers in cycles also
Fixed endless loop which could occur when using "relationship to aliased
class" feature and also indicating a recursive eager loader such as
``lazy="selectinload"`` in the loader, in combination with another eager
loader on the opposite side. The check for cycles has been fixed to include
aliased class relationships.
Mike Bayer [Sat, 18 Mar 2023 15:43:47 +0000 (11:43 -0400)]
implement content hashing for custom_op, not identity
Fixed critical SQL caching issue where use of the :meth:`_sql.Operators.op`
custom operator function would not produce an appropriate cache key,
leading to reduce the effectiveness of the SQL cache.
Mike Bayer [Wed, 8 Mar 2023 15:10:14 +0000 (10:10 -0500)]
additional consistency for ORM/Core in tutorial
* Make sure we have blue borders for all sections
* rewrite "blue border" text, refer to textual means of determining
subject matter for a section; "blue borders" are not a primary
source of information
* Add some more intro text that was missing
Grey Li [Sun, 26 Feb 2023 10:56:37 +0000 (05:56 -0500)]
Add separate version notes for scalars
Add separate 1.4.24 and 1.4.26 version notes for the .scalars method;
this covers Session, scoped_session, AsyncSession, async_scoped_session
as the "scoped" versions did not have the method added until 1.4.26
as part of :ticket:`7103`.
Also indicate scoped_session as ``sqlalchemy.orm.scoped_session`` in
docs rather than ``sqlalchemy.orm.scoping.scoped_session``. This is
also happening in I77da54891860095edcb1f0625ead99fee89bd76f separately,
as both changesets refer to scoped_session without using ".scoping".
Mike Bayer [Thu, 9 Feb 2023 17:05:47 +0000 (12:05 -0500)]
pin sphinx-copybutton and change config
sphinx-copybutton introduced a new feature
in 0.5.1 which includes a default configuration
that breaks the regexp prompt matching scheme.
set copybutton_exclude to not include ".gp" as that's the class
where we exactly look for the prompts we are matching.
While we're there, use this new feature to exclude our sql
styles, even though this is not strictly necessary in our case.
pin sphinx-copybutton at 0.5.1 to avoid future problems.
Change-Id: I8eaeab13995c032b9ee3afd1f08dae5929009d45
References: https://github.com/executablebooks/sphinx-copybutton/issues/185
(cherry picked from commit 13d3b2c291f49525bc38d082d1c2abe9e03bd3fe)
Mike Bayer [Sat, 28 Jan 2023 14:37:50 +0000 (09:37 -0500)]
Correct #7664 to include DropSchema
Corrected the fix for :ticket:`7664`, released in version 2.0.0, to also
include :class:`.DropSchema` which was inadvertently missed in this fix,
allowing stringification without a dialect. The fixes for both constructs
is backported to the 1.4 series as of 1.4.47.
Shan [Sun, 22 Jan 2023 16:19:11 +0000 (11:19 -0500)]
Run bracket interpretation for reflection
Fixed bug where a schema name given with brackets, but no dots inside the
name, for parameters such as :paramref:`_schema.Table.schema` would not be
interpreted within the context of the SQL Server dialect's documented
behavior of interpreting explicit brackets as token delimiters, first added
in 1.2 for #2626, when referring to the schema name in reflection
operations. The original assumption for #2626's behavior was that the
special interpretation of brackets was only significant if dots were
present, however in practice, the brackets are not included as part of the
identifier name for all SQL rendering operations since these are not valid
characters within regular or delimited identifiers. Pull request courtesy
Shan.
Mike Bayer [Tue, 17 Jan 2023 01:17:50 +0000 (20:17 -0500)]
mypy plugin fixes
Adjustments made to the mypy plugin to accommodate for some potential
changes being made for issue #236 sqlalchemy2-stubs when using SQLAlchemy
1.4. These changes are being kept in sync within SQLAlchemy 2.0.
The changes are also backwards compatible with older versions of
sqlalchemy2-stubs.
Fixed crash in mypy plugin which could occur on both 1.4 and 2.0 versions
if a decorator for the :func:`_orm.registry.mapped` decorator were used
that was referenced in an expression with more than two components (e.g.
``@Backend.mapper_registry.mapped``). This scenario is now ignored; when
using the plugin, the decorator expression needs to be two components (i.e.
``@reg.mapped``).
Mike Bayer [Thu, 12 Jan 2023 16:25:39 +0000 (11:25 -0500)]
add with_loader_criteria() test for #8064 / #9091
test related to #8064, added after discussion #9091 which
requested this behavior for with_loader_criteria() where it was
found to be working as of this issue, just not tested
Mike Bayer [Tue, 10 Jan 2023 14:51:23 +0000 (09:51 -0500)]
fix ORM support for column-named bindparam() in crud .values()
Fixed bug / regression where using :func:`.bindparam()` with the same name
as a column in the :meth:`.Update.values` method of :class:`.Update`, as
well as the :meth:`.Insert.values` method of :class:`.Insert` in 2.0 only,
would in some cases silently fail to honor the SQL expression in which the
parameter were presented, replacing the expression with a new parameter of
the same name and discarding any other elements of the SQL expression, such
as SQL functions, etc. The specific case would be statements that were
constructed against ORM entities rather than plain :class:`.Table`
instances, but would occur if the statement were invoked with a
:class:`.Session` or a :class:`.Connection`.
:class:`.Update` part of the issue was present in both 2.0 and 1.4 and is
backported to 1.4.
For 1.4, also backports the sqlalchemy.testing.Variation update
to the variation() API.
Michael Gorven [Wed, 4 Jan 2023 17:30:42 +0000 (12:30 -0500)]
[asyncpg] Extract rowcount for SELECT statements
Added support to the asyncpg dialect to return the ``cursor.rowcount``
value for SELECT statements when available. While this is not a typical use
for ``cursor.rowcount``, the other PostgreSQL dialects generally provide
this value. Pull request courtesy Michael Gorven.