Mike Bayer [Tue, 31 Oct 2023 18:56:37 +0000 (14:56 -0400)]
use _extra_criteria to store with_expression() expression
this is an alternate version of the first patch, which adds extra
handling for the "expression" in local_opts. this patch has
with_expression() use _extra_criteria directly, as this attribute
is currently unpurposed for column-based attributes.
Fixed caching bug where using the :func:`_orm.with_expression` construct in
conjunction with loader options :func:`_orm.selectinload`,
:func:`_orm.lazyload` would fail to substitute bound parameter values
correctly on subsequent caching runs.
Mike Bayer [Tue, 31 Oct 2023 02:14:21 +0000 (22:14 -0400)]
add note that secondary string is Python eval re: identifier names
im not exactly sure why "secondary" string is a Python eval
as I dont know what kind of Python eval someone might put there.
Add explicit note about this referring to table names that have
non-Python identifier characters.
Sören Oldag [Thu, 26 Oct 2023 13:17:41 +0000 (09:17 -0400)]
Add bind casts for BIT on asyncpg
Fixed SQL handling for "insertmanyvalues" when using the
:class:`.postgresql.BIT` datatype with the asyncpg backend. The
:class:`.postgresql.BIT` on asyncpg apparently requires the use of an
asyncpg-specific `BitString` type which is currently exposed when using
this DBAPI, making it incompatible with other PostgreSQL DBAPIs that all
work with plain bitstrings here. A future fix in version 2.1 will
normalize this datatype across all PG backends. Pull request courtesy
Sören Oldag.
Mike Bayer [Tue, 24 Oct 2023 20:05:48 +0000 (16:05 -0400)]
remove type check decorators
in 598ae1d120a35ee9e19cf7f953c7dd51047954d6, we erroneously
merged "no_type_check" decorators. we only merge typing that works
or requires "type: ignore", so remove these
add literal_processors for interval, PG and Oracle
Implemented "literal value processing" for the :class:`.Interval` datatype
for both the PostgreSQL and Oracle dialects, allowing literal rendering of
interval values. Pull request courtesy Indivar Mishra.
Mike Bayer [Tue, 24 Oct 2023 16:06:24 +0000 (12:06 -0400)]
accommodate NULL at the compiler level for literal_render
Added compiler-level None/NULL handling for the "literal processors" of all
datatypes that include literal processing, that is, where a value is
rendered inline within a SQL statement rather than as a bound parameter,
for all those types that do not feature explicit "null value" handling.
Previously this behavior was undefined and inconsistent.
indivar [Fri, 20 Oct 2023 15:25:38 +0000 (11:25 -0400)]
use oracle.INTERVAL for generic interval
Fixed issue in :class:`.Interval` datatype where the Oracle implementation
was not being used for DDL generation, leading to the ``day_precision`` and
``second_precision`` parameters to be ignored, despite being supported by
this dialect. Pull request courtesy Indivar.
Mike Bayer [Fri, 20 Oct 2023 14:19:35 +0000 (10:19 -0400)]
run declarative scan for non-mapped annotated if allow_unmapped
Fixed issue where the ``__allow_unmapped__`` directive failed to allow for
legacy :class:`.Column` / :func:`.deferred` mappings that nonetheless had
annotations such as ``Any`` or a specific type without ``Mapped[]`` as
their type, without errors related to locating the attribute name.
Mike Bayer [Thu, 19 Oct 2023 16:14:14 +0000 (12:14 -0400)]
manufacture empty result for DELETE..RETURNING w/ no description
Established a workaround for what seems to be an intrinsic issue across
MySQL/MariaDB drivers where a RETURNING result for DELETE DML which returns
no rows using SQLAlchemy's "empty IN" criteria fails to provide a
cursor.description, which then yields result that returns no rows,
leading to regressions for the ORM that in the 2.0 series uses RETURNING
for bulk DELETE statements for the "synchronize session" feature. To
resolve, when the specific case of "no description when RETURNING was
given" is detected, an "empty result" with a correct cursor description is
generated and used in place of the non-working cursor.
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 [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.
Bryan不可思议 [Wed, 18 Oct 2023 20:31:45 +0000 (16:31 -0400)]
fix AsyncSession.close_all()
Fixed bug with method :meth:`_asyncio.AsyncSession.close_all`
that was not working correctly.
Also added function :func:`_asyncio.close_all_sessions` that's
the equivalent of :func:`_orm.close_all_sessions`.
Federico Caselli [Wed, 18 Oct 2023 17:51:00 +0000 (19:51 +0200)]
Remove compare_against_backend
Removed unused placeholder method :meth:`.TypeEngine.compare_against_backend`
This method was used by very old versions of Alembic.
See https://github.com/sqlalchemy/alembic/issues/1293 for details.
Follow up of alembic change I6f480711ec94cd4113d3f0ca114d143b49b8d869
indivar [Mon, 16 Oct 2023 18:53:04 +0000 (14:53 -0400)]
fix(#10056): keep nullable as true for mariadb generated columns
mariaDB does not support setting NOT NULL for generated column
ref: https://mariadb.com/kb/en/generated-columns/#statement-support
added a check in `get_column_specification` for mariadb, checking
if user has not specified nullable set it as True for computed column,
but if user has explicitly set as False raise a compile error.
added testcase for same
<!-- 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:
- [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.
Mike Bayer [Mon, 16 Oct 2023 17:01:42 +0000 (13:01 -0400)]
implement eager_grouping for expression clauselists
the expression clauselist feature added in #7744 failed to accommodate
this parameter that is used only by the PostgreSQL JSON
operators.
Fixed 2.0 regression caused by :ticket:`7744` where chains of expressions
involving PostgreSQL JSON operators combined with other operators such as
string concatenation would lose correct parenthesization, due to an
implementation detail specific to the PostgreSQL dialect.
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
<!-- Describe your changes in detail -->
The `get_one()` method is described as raising an error if no row is found instead of returning `None` (as `get()` does). Also, the return type hint prohibits `None`.
### 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 [Fri, 13 Oct 2023 19:27:40 +0000 (15:27 -0400)]
ensure ClassVar succeeds in cleanup_mapped_str_annotation
Fixed bug in ORM annotated declarative where using a ``ClassVar`` that
nonetheless referred in some way to an ORM mapped class name would fail to
be interpreted as a ``ClassVar`` that's not mapped.
Mike Bayer [Fri, 13 Oct 2023 18:01:07 +0000 (14:01 -0400)]
amend cx_Oracle version checks, setup.cfg to oracle 8
Fixed issue where the cx_Oracle dialect claimed to support a lower
cx_Oracle version (7.x) than was actually supported in practice within the
2.0 series of SQLAlchemy. The dialect imports symbols that are only in
cx_Oracle 8 or higher, so runtime dialect checks as well as setup.cfg
requirements have been updated to reflect this compatibility.
Mike Bayer [Wed, 11 Oct 2023 22:06:17 +0000 (18:06 -0400)]
improve detection / errors for unknown hashability w/ unique
Fixed issue where calling :meth:`_engine.Result.unique` with a new-style
:func:`.select` query in the ORM, where one or more columns yields values
that are of "unknown hashability", typically when using JSON functions like
``func.json_build_object()`` without providing a type, would fail
internally when the returned values were not actually hashable. The
behavior is repaired to test the objects as they are received for
hashability in this case, raising an informative error message if not. Note
that for values of "known unhashability", such as when the :class:`.JSON`
or :class:`.ARRAY` types are used directly, an informative error message
was already raised.
The "hashabiltiy testing" fix here is applied to legacy :class:`.Query` as
well, however in the legacy case, :meth:`_engine.Result.unique` is used for
nearly all queries, so no new warning is emitted here; the legacy behavior
of falling back to using ``id()`` in this case is maintained, with the
improvement that an unknown type that turns out to be hashable will now be
uniqufied, whereas previously it would not.
Iuri de Silvio [Thu, 12 Oct 2023 12:25:40 +0000 (08:25 -0400)]
Make Values().data input covariant with Sequence
Fixed typing issue where the argument list passed to :class:`.Values` was
too-restrictively tied to ``List`` rather than ``Sequence``. Pull request
courtesy Iuri de Silvio.
Mike Bayer [Wed, 11 Oct 2023 19:36:24 +0000 (15:36 -0400)]
include ORDER BY in subquery that has TOP via FETCH
Fixed bug where the rule that prevents ORDER BY from emitting within
subqueries on SQL Server was not being disabled in the case where the
:meth:`.select.fetch` method were used to limit rows in conjunction with
WITH TIES or PERCENT, preventing valid subqueries with TOP / ORDER BY from
being used.
Mike Bayer [Wed, 11 Oct 2023 14:28:34 +0000 (10:28 -0400)]
dont enter do_executemany if implicit_returning is False
Fixed regression in recently revised "insertmanyvalues" feature (likely
issue :ticket:`9618`) where the ORM would inadvertently attempt to
interpret a non-RETURNING result as one with RETURNING, in the case where
the ``implicit_returning=False`` parameter were applied to the mapped
:class:`.Table`, indicating that "insertmanyvalues" cannot be used if the
primary key values are not provided.
This includes a refinement to insertmanyvalues where we consider
return_defaults() with supplemental_cols to be the same as an explicit
returning(), since that's the purpose of this. This saves us some
extra exceptions that could be thrown per-dialect if implicit_returning
were set to False in some cases.
Fixed issue within some dialects where the dialect could incorrectly return
an empty result set for an INSERT statement that does not actually return
rows at all, due to artfacts from pre- or post-fetching the primary key of
the row or rows still being present. Affected dialects included asyncpg,
all mssql dialects.
Jens Troeger [Sat, 7 Oct 2023 06:48:29 +0000 (02:48 -0400)]
Fix typo in Session.get_one() docs
<!-- Provide a general summary of your proposed changes in the Title field above -->
A typo in the docstrings [here](https://docs.sqlalchemy.org/en/20/orm/session_api.html#sqlalchemy.orm.Session.get_one) shows the incorrectly formatted text:

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.
Iuri de Silvio [Mon, 9 Oct 2023 12:21:01 +0000 (08:21 -0400)]
repair / test repr() for DDL
Fixed 2.0 regression where the :class:`.DDL` construct would no longer
``__repr__()`` due to the removed ``on`` attribute not being accommodated.
Pull request courtesy Iuri de Silvio.
Stefanie Molin [Fri, 6 Oct 2023 13:39:41 +0000 (09:39 -0400)]
Fix typos in pooling docs
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
<!-- Describe your changes in detail -->
- fixed typo in pooling doc that mentioned three items but had a list of 4
- fixed typo "whish" to "wish" in pooling doc
### 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 [Wed, 4 Oct 2023 13:42:55 +0000 (09:42 -0400)]
check fairy for None in pool cleanup
Fixed issue where under some garbage collection / exception scenarios the
connection pool's cleanup routine would raise an error due to an unexpected
set of state, which can be reproduced under specific conditions.
Mike Bayer [Tue, 3 Oct 2023 17:42:35 +0000 (13:42 -0400)]
include WriteOnlyMapped, DynamicMapped in abs import lookup
Fixed issue where :class:`.Mapped` symbols like :class:`.WriteOnlyMapped`
and :class:`.DynamicMapped` could not be correctly resolved when referenced
as an element of a sub-module in the given annotation, assuming
string-based or "future annotations" style annotations.
Mike Bayer [Tue, 3 Oct 2023 12:40:06 +0000 (08:40 -0400)]
consider indpendent CTE for UPDATE..FROM
Fixed issue where referring to a FROM entry in the SET clause of an UPDATE
statement would not include it in the FROM clause of the UPDATE statement,
if that entry were nowhere else in the statement; this occurs currently for
CTEs that were added using :meth:`.Update.add_cte` to provide the desired
CTE at the top of the statement.
Set to ``False`` the new parameter :paramref:`_orm.Session.close_is_reset`
will prevent a :class:`_orm.Session` from performing any other
operation after :meth:`_orm.Session.close` has been called.
Added new method :meth:`_orm.Session.reset` that will reset a :class:`_orm.Session`
to its initial state. This is an alias of :meth:`_orm.Session.close`,
unless :paramref:`_orm.Session.close_is_reset` is set to ``False``.
Carlos Sousa [Mon, 25 Sep 2023 17:03:26 +0000 (13:03 -0400)]
Add get_one to Session, AsyncSession, scoped, etc
Added method :meth:`_orm.Session.get_one` that behaves like
meth:`_orm.Session.get` but raises an exception instead of returning
None`` if no instance was found with the provided primary key.
Pull request courtesy of Carlos Sousa.
Fixed the :paramref:`_asyncio.AsyncSession.get.execution_options` parameter
which was not being propagated to the underlying :class:`_orm.Session` and
was instead being ignored.
Mike Bayer [Thu, 28 Sep 2023 12:58:16 +0000 (08:58 -0400)]
invoke mariadb-connector .rowcount after all statements
Modified the mariadb-connector driver to pre-load the ``cursor.rowcount``
value for all queries, to suit tools such as Pandas that hardcode to
calling :attr:`.Result.rowcount` in this way. SQLAlchemy normally pre-loads
``cursor.rowcount`` only for UPDATE/DELETE statements and otherwise passes
through to the DBAPI where it can return -1 if no value is available.
However, mariadb-connector does not support invoking ``cursor.rowcount``
after the cursor itself is closed, raising an error instead. Generic test
support has been added to ensure all backends support the allowing
:attr:`.Result.rowcount` to succceed (that is, returning an integer value
with -1 for "not available") after the result is closed.
This change also restores mariadb-connector to CI including
as part of the "dbdriver" suite; in 366a5e3e2e503a20ef0334fbf9f we had
taken it out of the DBAPI main job.
Additional fixes for the mariadb-connector dialect to support UUID data
values in the result in INSERT..RETURNING statements.
Added rounding to one remaining INSERT..RETURNING with floats test
to allow mariadbconnector to pass (likely similar issue as the one with
UUID but not worth making a new handler)
handle builtins types in annotations with __allow_unmapped__
Fixed issue with ``__allow_unmapped__`` declarative option where types that
were declared using collection types such as ``list[SomeClass]`` vs. the
typing construct ``List[SomeClass]`` would fail to be recognized correctly.
Pull request courtesy Pascal Corpet.
Mike Bayer [Wed, 27 Sep 2023 21:39:45 +0000 (17:39 -0400)]
back out pymssql for py312
in ff80019212a5632c9dd01e we opened up for py312.
all the drivers passed except the mssql build as there is no wheel for
pymssql and we have not been able to build that one.
Mike Bayer [Wed, 27 Sep 2023 15:27:47 +0000 (11:27 -0400)]
open up py312 for all DBAPIs
this wont run under jenkins gerrit job but will hit for jenkins_main /
jenkins_dbapi_main. will merge and then revert if main / github
builds are really tanking
Eric Hanchrow [Wed, 20 Sep 2023 21:02:08 +0000 (17:02 -0400)]
Revise / rewrite sentences that use the phrase "referred towards"
Comments by Mike <mike_mp@zzzcomputing.com>:
"Referred towards" is not correct English and can be replaced directly
with "referred to". However, this then introduces a dangling
preposition to sentences which I don't think is appropriate for this
style of writing. So instead, use phrases like "known as",
"references", "to which X refers".
To help me identify dangling prepositions I made use of ChatGPT,
here's the log of how that transpired:
https://chat.openai.com/share/60d42ff4-c1ac-4232-893a-415c2b6d7320
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Closes: #10210
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10210
Pull-request-sha: 5d30e79c14fe78996d332fefd4bae36d76626ff4
Mike Bayer [Tue, 19 Sep 2023 21:57:50 +0000 (17:57 -0400)]
accommodate all mapped_column() parameters in Annotated transfer
Fixed a wide range of :func:`_orm.mapped_column` parameters that were not
being transferred when using the :func:`_orm.mapped_column` object inside
of a pep-593 ``Annotated`` object, including
:paramref:`_orm.mapped_column.sort_order`,
:paramref:`_orm.mapped_column.deferred`,
:paramref:`_orm.mapped_column.autoincrement`,
:paramref:`_orm.mapped_column.system`, :paramref:`_orm.mapped_column.info`
etc.
Additionally, it remains not supported to have dataclass arguments, such as
:paramref:`_orm.mapped_column.kw_only`,
:paramref:`_orm.mapped_column.default_factory` etc. indicated within the
:func:`_orm.mapped_column` received by ``Annotated``, as this is not
supported with pep-681 Dataclass Transforms. A warning is now emitted when
these parameters are used within ``Annotated`` in this way (and they
continue to be ignored).
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.