Mike Bayer [Wed, 4 Sep 2024 03:08:21 +0000 (23:08 -0400)]
use proper functions to get typing origin, args
Fixed regression caused by issue :ticket:`11814` which broke support for
certain flavors of :pep:`593` ``Annotated`` in the type_annotation_map when
builtin types such as ``list``, ``dict`` were used without an element type.
While this is an incomplete style of typing, these types nonetheless
previously would be located in the type_annotation_map correctly.
Mike Bayer [Mon, 2 Sep 2024 15:22:36 +0000 (11:22 -0400)]
add "The server failed to resume the transaction" to pymssql
Added error "The server failed to resume the transaction" to the list of
error strings for the pymssql driver in determining a disconnect scenario,
as observed by one user using pymssql under otherwise unknown conditions as
leaving an unusable connection in the connection pool which fails to ping
cleanly.
Mike Bayer [Mon, 2 Sep 2024 14:37:29 +0000 (10:37 -0400)]
dont erase transaction if rollback/commit failed outside of asyncpg
Fixed critical issue in the asyncpg driver where a rollback or commit that
fails specifically for the ``MissingGreenlet`` condition or any other error
that is not raised by asyncpg itself would discard the asyncpg transaction
in any case, even though the transaction were still idle, leaving to a
server side condition with an idle transaction that then goes back into the
connection pool. The flags for "transaction closed" are now not reset for
errors that are raised outside of asyncpg itself. When asyncpg itself
raises an error for ``.commit()`` or ``.rollback()``, asyncpg does then
discard of this transaction.
The pin for ``setuptools<69.3`` in ``pyproject.toml`` has been
removed. This pin was to prevent a sudden change to :pep:`625` in
setuptools from taking place which changes the file name of SQLAlchemy's
source distribution on pypi to be an all lower case name, which is very
likely to cause problems with various build environments that expected a
particular naming style. However, the presence of this pin is now holding
back environments that otherwise want to use a newer setuptools, so we've
decided to move forward with this change, with the assumption that build
environments will have largely accommodated the setuptools change by
now.
Mike Bayer [Mon, 2 Sep 2024 15:18:35 +0000 (11:18 -0400)]
add asyncio.CancelledError to terminate conditions
Revising the asyncpg ``terminate()`` fix first made in :ticket:`10717`
which improved the resiliency of this call under all circumstances, adding
``asyncio.CancelledError`` to the list of exceptions that are intercepted
as failing for a graceful ``.close()`` which will then proceed to call
``.terminate()``.
Mike Bayer [Sat, 31 Aug 2024 16:56:00 +0000 (12:56 -0400)]
re-process args for builtin generic types
Improvements to the ORM annotated declarative type map lookup dealing with
composed types such as ``dict[str, Any]`` linking to JSON (or others) with
or without "future annotations" mode.
There's apparently a big incompatiblity in types from typing vs.
Python builtins in the way they genericize. The typing library makes
it very difficult to distinguish between the two sets of types. This
patch is a bit slash and burn to work around all this. These should
likely be reported as bugs in the Python standard library if they
aren't already.
Mike Bayer [Thu, 29 Aug 2024 14:04:47 +0000 (10:04 -0400)]
pass to_metadata argument to Enum.copy()
Fixed bug where the ``metadata`` element of an ``Enum`` datatype would not
be transferred to the new :class:`.MetaData` object when the type had been
copied via a :meth:`.Table.to_metadata` operation, leading to inconsistent
behaviors within create/drop sequences.
John A Stevenson [Mon, 26 Aug 2024 15:05:38 +0000 (11:05 -0400)]
Update SQLite UNIQUE inline constraint parsing to handle tabs
Improvements to the regex used by the SQLite dialect to reflect the name
and contents of a UNIQUE constraint that is defined inline within a column
definition inside of a SQLite CREATE TABLE statement, accommodating for tab
characters present within the column / constraint line. Pull request
courtesy John A Stevenson.
Mike Bayer [Mon, 19 Aug 2024 20:53:34 +0000 (16:53 -0400)]
try a new bug template.
i really dont want people opening issues, saying things like
"this is not correct", etc. Let's talk about the problem you
have and what's the ideal outcome. thanks
Jeff Horemans [Tue, 13 Aug 2024 15:22:51 +0000 (11:22 -0400)]
Reflect broader range of check constraints for SQLite.
Improvements to the regex used by the SQLite dialect to reflect the name
and contents of a CHECK constraint. Constraints with newline, tab, or
space characters in either or both the constraint text and constraint name
are now properly reflected. Pull request courtesy Jeff Horemans.
Mike Bayer [Mon, 12 Aug 2024 23:50:05 +0000 (19:50 -0400)]
de-memoize _proxy_key when new annotations are added
Fixed regression from 1.3 where the column key used for a hybrid property
might be populated with that of the underlying column that it returns, for
a property that returns an ORM mapped column directly, rather than the key
used by the hybrid property itself.
Mike Bayer [Tue, 13 Aug 2024 13:13:51 +0000 (09:13 -0400)]
omit mysql8 dupe key alias for INSERT..FROM SELECT
Fixed issue in MySQL dialect where using INSERT..FROM SELECT in combination
with ON DUPLICATE KEY UPDATE would erroneously render on MySQL 8 and above
the "AS new" clause, leading to syntax failures. This clause is required
on MySQL 8 to follow the VALUES clause if use of the "new" alias is
present, however is not permitted to follow a FROM SELECT clause.
Mike Bayer [Sun, 11 Aug 2024 19:41:36 +0000 (15:41 -0400)]
turn off pyodbc pooling
new updates of unixodbc are turning this on in CI revealing
that our isolation level tests assume no pooling takes place,
so disable this, which is only at global module level for pyodbc
Masterchen09 [Tue, 6 Aug 2024 18:20:51 +0000 (14:20 -0400)]
handle quoted_name instances separately in engine.reflection.cache
Fixed issue in internal reflection cache where particular reflection
scenarios regarding same-named quoted_name() constructs would not be
correctly cached. Pull request courtesy Felix Lüdin.
Mike Bayer [Wed, 7 Aug 2024 16:18:25 +0000 (12:18 -0400)]
restore generative to with_statement_hint
Fixed regression in :meth:`_sql.Select.with_statement_hint` and others
where the generative behavior of the method stopped producing a copy of the
object.
Added support for server-side cursor in oracledb async dialect.
Added API support for server-side cursors for the oracledb async dialect,
allowing use of the :meth:`_asyncio.AsyncConnection.stream` and similar
stream methods.
Mike Bayer [Thu, 1 Aug 2024 19:58:57 +0000 (15:58 -0400)]
skip in eager row processors for enable_eagerloads=False
Fixed issue where using the :meth:`_orm.Query.enable_eagerloads` and
:meth:`_orm.Query.yield_per` methods at the same time, in order to disable
eager loading that's configured on the mapper directly, would be silently
ignored, leading to errors or unexpected eager population of attributes.
Mike Bayer [Thu, 1 Aug 2024 20:41:45 +0000 (16:41 -0400)]
add check for pre-existing history records
Fixed issue in history_meta example where the "version" column in the
versioned table needs to default to the most recent version number in the
history table on INSERT, to suit the use case of a table where rows are
deleted, and can then be replaced by new rows that re-use the same primary
key identity. This fix adds an additonal SELECT query per INSERT in the
main table, which may be inefficient; for cases where primary keys are not
re-used, the default function may be omitted. Patch courtesy Philipp H.
v. Loewenfeld.
Mike Bayer [Thu, 1 Aug 2024 13:49:55 +0000 (09:49 -0400)]
mutate lists in place for return_defaults=True
Fixed regression from version 1.4 in
:meth:`_orm.Session.bulk_insert_mappings` where using the
:paramref:`_orm.Session.bulk_insert_mappings.return_defaults` parameter
would not populate the passed in dictionaries with newly generated primary
key values.
Federico Caselli [Mon, 10 Jun 2024 19:20:56 +0000 (21:20 +0200)]
Add support for two-phase commit in oracledb.
Implemented two-phase transactions for the oracledb dialect. Historically,
this feature never worked with the cx_Oracle dialect, however recent
improvements to the oracledb successor now allow this to be possible. The
two phase transaction API is available at the Core level via the
:meth:`_engine.Connection.begin_twophase` method.
As part of this change, added new facility for testing that allows
a test to skip if a certain step takes too long, allowing for a
separate cleanup step. this is needed as oracle tpc wont allow
commit recovery if transaction is older than about 1 second, could not
find any docs on how to increase this timeout.
Fixed an execute call in the PostgreSQL dialect's provisioning that
drops old tpc transactions which was non-working, which indicates
that we've apparently never had any PG tpc transactions needing to
be cleaned up in CI for some years now, so that's good
Fixed compilation of bitwise operators on oracle and sqlite.
Implemented bitwise operators for Oracle which was previously
non-functional due to a non-standard syntax used by this database.
Oracle's support for bitwise "or" and "xor" starts with server version 21.
Additionally repaired the implementation of "xor" for SQLite.
As part of this change, the dialect compliance test suite has been enhanced
to include support for server-side bitwise tests; third party dialect
authors should refer to new "supports_bitwise" methods in the
requirements.py file to enable these tests.
Federico Caselli [Fri, 14 Jun 2024 22:06:46 +0000 (00:06 +0200)]
add CTE cache elements for CompoundSelect, more verify tests
Follow up of :ticket:`11471` to fix caching issue where using the
:meth:`.CompoundSelectState.add_cte` method of the
:class:`.CompoundSelectState` construct would not set a correct cache key
which distinguished between different CTE expressions. Also added tests
that would detect issues similar to the one fixed in :ticket:`11544`.
Mike Bayer [Sat, 20 Jul 2024 02:59:35 +0000 (22:59 -0400)]
restore transfer of mapper.local_table to DML for some cases
Fixed regression appearing in 2.0.21 caused by :ticket:`10279` where using
a :func:`_sql.delete` or :func:`_sql.update` against an ORM class that is
the base of an inheritance hierarchy, while also specifying that subclasses
should be loaded polymorphically, would leak the polymorphic joins into the
UPDATE or DELETE statement as well creating incorrect SQL.
This re-introduces logic to set the `.table` of an ORM update or delete
back to `mapper.local_table` that was removed in d18ccdc997185b74 by
:ticket:`10279`; the logic is qualified to only take place for a
statement that's directly against a mapper and not one that's against
an aliased object.
Fixed internal typing issues to establish compatibility with mypy 1.11.0.
Note that this does not include issues which have arisen with the
deprecated mypy plugin used by SQLAlchemy 1.4-style code; see the addiional
change note for this plugin indicating revised compatibility.
The legacy mypy plugin is no longer fully functional with the latest series
of mypy 1.11.0, as changes in the mypy interpreter are no longer compatible
with the approach used by the plugin. If code is dependent on the legacy
mypy plugin with sqlalchemy2-stubs, it's recommended to pin mypy to be
below the 1.11.0 series. Seek upgrading to the 2.0 series of SQLAlchemy
and migrating to the modern type annotations.
Mike Bayer [Wed, 10 Jul 2024 14:32:44 +0000 (10:32 -0400)]
include nulls_first, nulls_last in order_by_label_element
Fixed bug where the :meth:`.Operators.nulls_first()` and
:meth:`.Operators.nulls_last()` modifiers would not be treated the same way
as :meth:`.Operators.desc()` and :meth:`.Operators.asc()` when determining
if an ORDER BY should be against a label name already in the statement. All
four modifiers are now treated the same within ORDER BY.
Mike Bayer [Fri, 5 Jul 2024 13:30:10 +0000 (09:30 -0400)]
alter the collation of string type for collate()
Fixed issue where the :func:`_sql.collate` construct, which explicitly sets
a collation for a given expression, would maintain collation settings for
the underlying type object from the expression, causing SQL expressions to
have both collations stated at once when used in further expressions for
specific dialects that render explicit type casts, such as that of asyncpg.
The :func:`_sql.collate` construct now assigns its own type to explicitly
include the new collation, assuming it's a string type.
Mike Bayer [Wed, 3 Jul 2024 19:46:30 +0000 (15:46 -0400)]
add special rule to honor UPPERCASE name for TExtualSelect
Fixed issue in name normalization (e.g. "uppercase" backends like Oracle)
where using a :class:`.TextualSelect` would not properly maintain as
uppercase column names that were quoted as uppercase, even though
the :class:`.TextualSelect` includes a :class:`.Column` that explicitly
holds this uppercase name.
* Added valid types to server_onupdate and mapped_column kwargs mypy tests
* Joined mapped_column test files
* Set _ServerOnUpdateArgument to _ServerDefaultArgument
Eric Atkin [Wed, 3 Jul 2024 20:05:04 +0000 (16:05 -0400)]
Allow flat for join with name
The :paramref:`_orm.aliased.name` parameter to :func:`_orm.aliased` may now
be combined with the :paramref:`_orm.aliased.flat` parameter, producing
per-table names based on a name-prefixed naming convention. Pull request
courtesy Eric Atkin.
Mike Bayer [Thu, 21 Dec 2023 17:14:00 +0000 (12:14 -0500)]
use driver col names
Added new execution option
:paramref:`_engine.Connection.execution_options.driver_column_names`. This
option disables the "name normalize" step that takes place against the
DBAPI ``cursor.description`` for uppercase-default backends like Oracle,
and will cause the keys of a result set (e.g. named tuple names, dictionary
keys in :attr:`.Row._mapping`, etc.) to be exactly what was delivered in
cursor.description. This is mostly useful for plain textual statements
using :func:`_sql.text` or :meth:`_engine.Connection.exec_driver_sql`.
Mike Bayer [Tue, 2 Jul 2024 17:57:47 +0000 (13:57 -0400)]
call iter() on detached/transient dynamic session
Fixed regression going back to 1.4 where accessing a collection using the
"dynamic" strategy on a transient object and attempting to query would
raise an internal error rather than the expected :class:`.NoResultFound`
that occurred in 1.3.
Mike Bayer [Fri, 28 Jun 2024 20:30:57 +0000 (16:30 -0400)]
handle DBAPI error for fetchall()
Fixed issue in "insertmanyvalues" feature where a particular call to
``cursor.fetchall()`` were not wrapped in SQLAlchemy's exception wrapper,
which apparently can raise a database exception during fetch when using
pyodbc.
lonkeknol [Fri, 28 Jun 2024 16:27:33 +0000 (12:27 -0400)]
Docs: simplify language in getting a connection & committing changes
### Description
Simplifies language use in [Getting a Connection](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#getting-a-connection) and [Committing Changes](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#committing-changes)
### 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, 27 Jun 2024 22:17:47 +0000 (18:17 -0400)]
cache key share; support correct traverse of 'of'
Fixed caching issue where the
:paramref:`_sql.Select.with_for_update.key_share` element of
:meth:`_sql.Select.with_for_update` was not considered as part of the cache
key, leading to incorrect caching if different variations of this parameter
were used with an otherwise identical statement.
Also repairs a traversal issue where the ``of`` element of
``ForUpdateArg`` when set to ``None`` cannot be compared against a
non-None element because the traversal defines it as a clauselist.
Traversal in this case is adjusted to accommodate for this case so that
we dont need to create a risky-to-backport change to ``ForUpdateArg``
itself.
lonkeknol [Thu, 27 Jun 2024 13:03:30 +0000 (09:03 -0400)]
Docs: simplify language use for "Working with Transactions and the DBAPI"
### Description
This is my first pull request to sqlalchemy. It changes the writing style of two paragraphs in the unified tutorial [here](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#working-with-transactions-and-the-dbapi). My goals were to.
1. Make them easier to read
2. Not change the meaning of the text.
3. Get feedback on whether this type of contribution is considered useful for sqlalchemy.
If this is a useful type of contribution, it might be good to discuss some general guidelines for me to adhere to as I continue. For instance:
- Prefer using present simple tense
- Remove superfluous words where possible
- Keep the pull requests to one or two h2 sections at a time, to make the review easier
### 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.
I'm curious to hear what you all think. **Have a nice day!**
Mike Bayer [Wed, 26 Jun 2024 16:13:28 +0000 (12:13 -0400)]
add additional test cases re: #11371
Just want to make sure aliased() and with_polymorphic() still
work in the of_type() context here, since that's likely why we
had Any for this parameter in the first place