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.
Mike Bayer [Tue, 12 Sep 2023 15:05:48 +0000 (11:05 -0400)]
parse for parenthesis in referenced tablename, columnname
Fixed a series of reflection issues affecting the PostgreSQL,
MySQL/MariaDB, and SQLite dialects when reflecting foreign key constraints
where the target column contained parenthesis in one or both of the table
name or column name.
Janek Nouvertné [Wed, 16 Aug 2023 15:01:39 +0000 (11:01 -0400)]
Update type annotations for loading options
Update type annotations for ORM loading options, restricting them to accept
only `"*"` instead of any string for string arguments. Pull request
courtesy Janek Nouvertné.
Fix typing to ensure that InstrumentedAttribute is hashable
Repaired the core "SQL element" class ``SQLCoreOperations`` to support the
``__hash__()`` method from a typing perspective, as objects like
:class:`.Column` and ORM :class:`.InstrumentedAttribute` are hashable and
are used as dictionary keys in the public API for the :class:`_dml.Update`
and :class:`_dml.Insert` constructs. Previously, type checkers were not
aware the root SQL element was hashable.
Mike Bayer [Thu, 14 Sep 2023 14:48:03 +0000 (10:48 -0400)]
consider _ClassStrategyLoad as part of endpoint path
Added new capability to the :func:`_orm.selectin_polymorphic` loader option
which allows other loader options to be bundled as siblings, referring to
one of its subclasses, within the sub-options of parent loader option.
Previously, this pattern was only supported if the
:func:`_orm.selectin_polymorphic` were at the top level of the options for
the query. See new documentation section for example.
As part of this change, improved the behavior of the
:meth:`_orm.Load.selectin_polymorphic` method / loader strategy so that the
subclass load does not load most already-loaded columns from the parent
table, when the option is used against a class that is already being
relationship-loaded. Previously, the logic to load only the subclass
columns worked only for a top level class load.
Mike Bayer [Tue, 12 Sep 2023 16:24:14 +0000 (12:24 -0400)]
qualify hashlib.md5() with usedforsecurity=False
Qualified the use of ``hashlib.md5()`` within the DDL compiler, which is
used to generate deterministic four-character suffixes for long index and
constraint names in DDL statements, to include the Python 3.9+
``usedforsecurity=False`` parameter so that Python interpreters built for
restricted environments such as FIPS do not consider this call to be
related to security concerns.
Mike Bayer [Tue, 12 Sep 2023 12:01:54 +0000 (08:01 -0400)]
allow any key for naming_convention dict, typing is not possible
Fixed regression introduced in 2.0.20 via :ticket:`9600` fix which
attempted to add more formal typing to
:paramref:`_schema.MetaData.naming_convention`. This change prevented basic
naming convention dictionaries from passing typing and has been adjusted so
that a plain dictionary of strings for keys as well as dictionaries that
use constraint types as keys or a mix of both, are again accepted.
As part of this change, lesser used forms of the naming convention
dictionary are also typed, including that it currently allows for
``Constraint`` type objects as keys as well.
Mike Bayer [Thu, 7 Sep 2023 21:37:13 +0000 (17:37 -0400)]
ensure all modules are importable without pytest harnesses
Fixed very old issue where the full extent of SQLAlchemy modules, including
``sqlalchemy.testing.fixtures``, could not be imported outside of a pytest
run. This suits inspection utilities such as ``pkgutil`` that attempt to
import all installed modules in all packages.
RomeoDespres [Tue, 29 Aug 2023 10:11:11 +0000 (06:11 -0400)]
Make `Mapped` covariant
Made the contained type for :class:`.Mapped` covariant; this is to allow
greater flexibility for end-user typing scenarios, such as the use of
protocols to represent particular mapped class structures that are passed
to other functions. As part of this change, the contained type was also
made covariant for dependent and related types such as
:class:`_orm.base.SQLORMOperations`, :class:`_orm.WriteOnlyMapped`, and
:class:`_sql.SQLColumnExpression`. Pull request courtesy Roméo Després.
within the change, there is a bit of adjustment to ``__radd__()`` to
match the typing of ``__add__()``, which previously was slightly
different for some reason and not passing on mypy with this change.
Mike Bayer [Fri, 25 Aug 2023 14:48:59 +0000 (10:48 -0400)]
automatically create proxy col for already-used col in values
The :class:`.Values` construct will now automatically create a proxy (i.e.
a copy) of a :class:`_sql.column` if the column were already associated
with an existing FROM clause. This allows that an expression like
``values_obj.c.colname`` will produce the correct FROM clause even in the
case that ``colname`` was passed as a :class:`_sql.column` that was already
used with a previous :class:`.Values` or other table construct.
Originally this was considered to be a candidate for an error condition,
however it's likely this pattern is already in widespread use so it's
now added to support.
* adjust unrelated dml test recently added for update..returning *
case to not rely upon ordering
Mike Bayer [Fri, 25 Aug 2023 16:12:06 +0000 (12:12 -0400)]
add explicit support for aliased ORM models in UPDATE/DELETE
Adjusted the ORM's interpretation of UPDATE/DELETE targets to not interfere
with the target table passed to the statement, such as for
:class:`_orm.aliased` constructs. Cases like ORM session synchonize using
"SELECT" statements such as with MySQL/ MariaDB will still have issues with
UPDATE/DELETE of this form so it's best to disable synchonize_session when
using DML statements of this type.
A separate issue to identify RETURNING should be used for
ORM UPDATE of an aliased() with fetch strategy and that these columns
should come back was attempted here, but is failing tests and is beyond
the scope of the immediate issue.
also updates the mssql URL in config to suit current preferences :)
Eugene Toder [Tue, 22 Aug 2023 17:54:02 +0000 (13:54 -0400)]
Allow using Enum with length=None
Adjusted the :class:`_types.Enum` datatype to accept an argument of
``None`` for the :paramref:`_types.Enum.length` parameter, resulting in a
VARCHAR or other textual type with no length in the resulting DDL. This
allows for new elements of any length to be added to the type after it
exists in the schema. Pull request courtesy Eugene Toder.
Jordan Macdonald [Wed, 16 Aug 2023 15:00:59 +0000 (11:00 -0400)]
Fix type hint of `key` on `Visitable.__class_getitem__()`
Fixed the type annotation for ``__class_getitem__()`` as applied to the
``Visitable`` class at the base of expression constructs to accept ``Any``
for a key, rather than ``str``, which helps with some IDEs such as PyCharm
when attempting to write typing annotations for SQL constructs which
include generic selectors. Pull request courtesy Jordan Macdonald.
Mike Bayer [Mon, 21 Aug 2023 14:40:09 +0000 (10:40 -0400)]
adjust concat precedence to match that of string comparison
Adjusted the operator precedence for the string concatenation operator to
be equal to that of string matching operators, such as
:meth:`.ColumnElement.like`, :meth:`.ColumnElement.regexp_match`,
:meth:`.ColumnElement.match`, etc., as well as plain ``==`` which has the
same precedence as string comparison operators, so that parenthesis will be
applied to a string concatenation expression that follows a string match
operator. This provides for backends such as PostgreSQL where the "regexp
match" operator is apparently of higher precedence than the string
concatenation operator.