Commit Graph

905 Commits

Author SHA1 Message Date
Michael Bayer 7fdada9c90 Merge "implement AsyncSessionTransaction._regenerate_proxy_for_target" into main 2025-03-27 16:29:58 +00:00
Mike Bayer 0202673a34 implement AsyncSessionTransaction._regenerate_proxy_for_target
Fixed issue where :meth:`.AsyncSession.get_transaction` and
:meth:`.AsyncSession.get_nested_transaction` would fail with
``NotImplementedError`` if the "proxy transaction" used by
:class:`.AsyncSession` were garbage collected and needed regeneration.

Fixes: #12471
Change-Id: Ia8055524618df706d7958786a500cdd25d9d8eaf
2025-03-27 11:11:04 -04:00
Kaan 7e28adbe0c Implement GROUPS frame spec for window functions
Implemented support for the GROUPS frame specification in window functions
by adding :paramref:`_sql.over.groups` option to :func:`_sql.over`
and :meth:`.FunctionElement.over`. Pull request courtesy Kaan Dikmen.

Fixes: #12450
Closes: #12445
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12445
Pull-request-sha: c0808e135f

Change-Id: I9ff504a9c9650485830c4a0eaf44162898a3a2ad
2025-03-27 13:34:52 +00:00
Federico Caselli 1ebd8c525b remove deprecated features
Remove feature deprecates in 1.3 and before

Fixes: #12441
Change-Id: Ice3d35ec02988ce94cdeb9db41cb684db2fb5d8d
2025-03-18 09:17:07 -04:00
Mike Bayer 5ec437a905 remove non_primary parameter
The "non primary" mapper feature, long deprecated in SQLAlchemy since
version 1.3, has been removed.   The sole use case for "non primary"
mappers was that of using :func:`_orm.relationship` to link to a mapped
class against an alternative selectable; this use case is now suited by the
:doc:`relationship_aliased_class` feature.

Fixes: #12437
Change-Id: I6987da06beb1d88d6f6e9696ce93e7fc340fc0ef
2025-03-17 12:58:46 -04:00
Federico Caselli 9b9e1e127f test related fixes
improve test error logging
add order to test

Change-Id: I2003f256a2690ee5673c72e2f1cb1340af750f83
2025-03-05 20:41:48 +01:00
Mike Bayer d9b4d8ff3a ensure compiler is not optional in create_for_statement()
this involved moving some methods around and changing the
target of legacy orm/query.py calling upon this method to
use an ORM-specific method instead

Change-Id: Ib977f08e52398d0e082acf7d88abecb9908ca8b6
2025-03-03 17:38:42 -05:00
allenyuchen ca092e73a2 fix(AsyncResult): Fix scalar method error due to missing attribute
Fixed bug where :meth:`_asyncio.AsyncResult.scalar`,
:meth:`_asyncio.AsyncResult.scalar_one_or_none`, and
:meth:`_asyncio.AsyncResult.scalar_one` would raise an ``AttributeError``
due to a missing internal attribute.  Pull request courtesy Allen Ho.

Fixes: #12338
Closes: #12339
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12339
Pull-request-sha: 63ba43365e

Change-Id: I44a949e4a942a080338037cd570d4b1dc0d7550d
2025-02-12 14:43:11 -05:00
Federico Caselli d69765829c Removed the deprecated mypy plugin.
The plugin was non-functional with newer version of mypy and it's no
longer needed with modern SQLAlchemy declarative style.

Fixes: #12293
Change-Id: If4581ab58623f0a2992f4e33a6dcdae002c68dad
2025-01-30 22:17:12 +01:00
Nils Philippsen 2e5a6cccc6 Skip mypy plugin tests if incompatible or missing
Fixes: #12287

<!-- Provide a general summary of your proposed changes in the Title field above -->

### Description
<!-- Describe your changes in detail -->

This skips Mypy plugin tests if mypy is missing or an unsupported version.

### 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:

- [ ] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [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.
- [ ] 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.

**Have a nice day!**

Closes: #12288
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12288
Pull-request-sha: 00e00f321d

Change-Id: I492a93d3c586425e2cf53304520164dc1487a667
2025-01-30 08:10:55 -05:00
Mike Bayer 311e142ea6 Separate Numeric and Float
the :class:`.Numeric` and :class:`.Float` SQL types have been separated out
so that :class:`.Float` no longer inherits from :class:`.Numeric`; instead,
they both extend from a common mixin :class:`.NumericCommon`.  This
corrects for some architectural shortcomings where numeric and float types
are typically separate, and establishes more consistency with
:class:`.Integer` also being a distinct type.   The change should not have
any end-user implications except for code that may be using
``isinstance()`` to test for the :class:`.Numeric` datatype; third party
dialects which rely upon specific implementation types for numeric and/or
float may also require adjustment to maintain compatibility.

Fixes:  #5252
Change-Id: Iadc841340b3d97e3eb5f7e63f0a0cc3cb4e30f74
2024-12-09 14:29:26 -05:00
Mike Bayer f7e2b1a6e5 apply underscores to ORM class and def names
criteria used here is:

* The class or def should definitely not be used directly by
  a third party
* The class would never be the subject of an `isinstance()` check
* The class is not exposed as the type of a return value for a public
  function

A sweep through class and function names in the ORM renames many classes
and functions that have no intent of public visibility to be underscored.
This is to reduce ambiguity as to which APIs are intended to be targeted by
third party applications and extensions.  Third parties are encouraged to
propose new public APIs in Discussions to the extent they are needed to
replace those that have been clarified as private.

Fixes: #10497
Change-Id: I9900e759be8510e01bba2c25984b9f30dc1fa9c0
2024-11-18 14:56:07 -05:00
Federico Caselli 2adc79c077 Removed support for Python 3.8 since it's EOL.
Fixes: #12029
Change-Id: Ibb4efec9bab0225d03f6bf3fed661a3f2fc72cc7
2024-11-05 21:23:34 +01:00
Federico Caselli 0cca754f21 Remove test warning in python 3.13
Change-Id: Ib098754ef6d157e8dd1eac32b3cb114a9ca66e4a
2024-09-17 20:22:11 +02:00
Mike Bayer 10c073dc80 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.

Fixes: #11728
Change-Id: Ifb298e46a20f90f6b6a717674f142a87cbceb468
2024-08-13 10:01:44 -04:00
Federico Caselli ffb2e2d033 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.

Fixes: #10820

Change-Id: I861670ccc20a81ec5ee45132b8059fc2a0359087
2024-08-05 12:16:47 -04:00
Federico Caselli 156fef6113 update typing for mypy 1.11; pin plugin to <1.11
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.

Change-Id: Ib8fef93ede588430dc0f7ed44ef887649a415821
2024-07-27 12:20:32 -04:00
Federico Caselli 9f4f84ffdc Fix Over serialization
Fixed issue when serializing an :func:`_sql.over` clause with
unbounded range or rows.

Fixes: #11422
Change-Id: I52a9f72205fd9c7ef5620596c83551e73d5cee5b
2024-05-29 22:03:17 +02:00
Mike Bayer 01fbe18d5c correctly apply _set_binops_check_strict to AssociationProxy
Revised the set "binary" operators for the association proxy ``set()``
interface to correctly raise ``TypeError`` for invalid use of the ``|``,
``&``, ``^``, and ``-`` operators, as well as the in-place mutation
versions of these methods, to match the behavior of standard Python
``set()`` as well as SQLAlchemy ORM's "intstrumented" set implementation.

Fixes: #11349
Change-Id: I02442f8885107d115b7ecfa1ca716835a55d4db3
2024-05-02 19:24:34 -04:00
Eugene Toder d2a743d0bc Allow using AsyncEngine in compile
This works, so only need to update the type annotation.

This pull request is:

- [x] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed

Closes: #11103
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11103
Pull-request-sha: ba9e61a390

Change-Id: I3d08b930a8cae0539bf9b436d5e806d8912cdee0
2024-03-11 21:42:01 +01:00
Mike Bayer c449505f65 raise for asyncio-incompatible pool classes
An error is raised if a :class:`.QueuePool` or other non-asyncio pool class
is passed to :func:`_asyncio.create_async_engine`.  This engine only
accepts asyncio-compatible pool classes including
:class:`.AsyncAdaptedQueuePool`. Other pool classes such as
:class:`.NullPool` are compatible with both synchronous and asynchronous
engines as they do not perform any locking.

Fixes: #8771
Change-Id: I5843ccea7d824488492d1a9d46207b9f05330ae3
2024-02-16 10:02:07 -05:00
Federico Caselli 9b153ff18f Update black to 24.1.1
Change-Id: Iadaea7b798d8e99302e1acb430dc7b758ca61137
2024-01-31 21:54:59 +01:00
Federico Caselli dca7673fb6 Add oracledb_async driver support
Added support for :ref:`oracledb` in async mode.
The current implementation has some limitation, preventing
the support for :meth:`_asyncio.AsyncConnection.stream`.
Improved support if planned for the 2.1 release of SQLAlchemy.

Fixes: #10679

Change-Id: Iff123cf6241bcfa0fbac57529b80f933951be0a7
2024-01-02 19:17:33 +01:00
Mike Bayer 2ed32bbf89 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()``.

Fixes: #10813
Change-Id: I95ec698b6a1ba79555aa0b28e6bce65fedf3b1fe
2024-01-01 17:20:19 -05:00
Mike Bayer e20ee33358 add test illustrating workaround for #4376
Fixes: #4376
Change-Id: I5131b55a9859bb9d93949a5a90b65f519cd82122
2023-12-29 12:07:19 -05:00
Michael Bayer f660c73e7d Merge "Remove async_fallback mode" into main 2023-12-27 21:34:57 +00:00
Federico Caselli 3976537274 Remove async_fallback mode
Removed the async_fallback mode and await_fallback function.
Replace get_event_loop with Runner.
Removed the internal function ``await_fallback()``.
Renamed the internal function ``await_only()`` to ``await_()``.

Change-Id: Ib43829be6ebdb59b6c4447f5a15b5d2b81403fa9
2023-12-20 22:54:28 +01:00
Mike Bayer 99da5ebab3 use a standard function to check for iterable collections
Fixed 2.0 regression in :class:`.MutableList` where a routine that detects
sequences would not correctly filter out string or bytes instances, making
it impossible to assign a string value to a specific index (while
non-sequence values would work fine).

Fixes: #10784
Change-Id: I829cd2a1ef555184de8e6a752f39df65f69f6943
2023-12-20 15:41:54 -05:00
Federico Caselli 4da59c6f53 More python 3.7 removal cleanups
Change-Id: I6de7754361c649af323fa1a90fe29371c98b1541
2023-11-07 19:21:06 +01:00
Bryan不可思议 29948f6848 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`.

Fixes: #10421
Closes: #10429
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10429
Pull-request-sha: a35c29d412

Change-Id: If2c3f0130a71b239382c2ea11a3436788ee242be
2023-10-18 23:04:57 +02:00
mike bayer f81c1c213f Merge "Added an option to permanently close sessions." into main 2023-10-04 15:02:47 +00:00
Daniel Krzeminski 8c72495e4d Added an option to permanently close sessions.
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``.

Fixes: #7787
Closes: #10137
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10137
Pull-request-sha: 881241e19b

Change-Id: Ic3512874600daff4ed66bb0cd29a3a88f667d258
2023-10-02 22:52:26 +02:00
Carlos Sousa dc8b7cb5fd 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.

Fixes #10292
Closes: #10376
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10376
Pull-request-sha: 70e4505e93

Change-Id: I78eb9816c26446757b6c6c171df2e400777a3d36
2023-10-01 09:07:44 -04:00
semen603089 a1e8a26f33 AsyncConnection[AsyncSession].aclose implementation
Added new methods :meth:`_asyncio.AsyncConnection.aclose` as a synonym for
:meth:`_asyncio.AsyncConnection.close` and
:meth:`_asyncio.AsyncSession.aclose` as a synonym for
:meth:`_asyncio.AsyncSession.close` to the
:class:`_asyncio.AsyncConnection` and :class:`_asyncio.AsyncSession`
objects, to provide compatibility with Python standard library
``@contextlib.aclosing`` construct. Pull request courtesy Grigoriev Semyon.

Fixes: #9698
Closes: #10106
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10106
Pull-request-sha: 9dbe87324d

Change-Id: I861d1fd4586018c2bdd6b45d7918af4f7d48d193
2023-07-31 21:01:15 +00:00
mike bayer 8d40984356 Merge "Improve typing tests" into main 2023-06-28 02:55:19 +00:00
Federico Caselli c3acf8a5d2 Improve typing tests
Extract a fixture to run mypy on files
Move the plain files to test/typing
Move test files from stubs repository
Transform the fixture module in a package

Change-Id: I23acaecb84e7c4b9010259d44395dc1df83a9385
2023-06-27 23:50:25 +02:00
Mike Bayer bf5cb5268c add option to create scalar object on none attribute set
Added new option to :func:`.association_proxy`
:paramref:`.association_proxy.create_on_none_assignment`; when an
association proxy which refers to a scalar relationship is assigned the
value ``None``, and the referenced object is not present, a new object is
created via the creator.  This was apparently an undefined behavior in the
1.2 series that was silently removed.

Fixes: #10013
Change-Id: I3aae484b8cf5218588b1db63e691cd86214fbbad
2023-06-23 21:57:41 -04:00
Mike Bayer cb39c0109e 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

Change-Id: Ic1ee12927ae02c1936d1c2905db28b587c7fece7
2023-06-21 15:04:37 -04:00
Mike Bayer b880dca14a add correct descriptor methods to dynamic/writeonly
Fixed typing issue which prevented :class:`_orm.WriteOnlyMapped` and
:class:`_orm.DynamicMapped` attributes from being used fully within ORM
queries.

Fixes: #9985
Change-Id: I33eef4d06fc84e85f2ea1a997a017ffce47df7d6
2023-06-21 13:07:31 -04:00
Mike Bayer f79d09221b updates for mypy 1.4
mypy 1.4 is reporting new style types list[], tuple[], etc.
as well as "x | None" for optional.

they also added one argument for format_type().

This is for 1.4 backport as well

Change-Id: I68084199858e9da901641d6036780437bcf5f2d6
2023-06-21 11:44:18 -04:00
Mike Bayer 108f5ec3fe improve support for declared_attr returning ORMDescriptor
Fixed issue in ORM Annotated Declarative which prevented a
:class:`_orm.declared_attr` with or without
:attr:`_orm.declared_attr.directive` from being used on a mixin which did
not return a :class:`.Mapped` datatype, and instead returned a supplemental
ORM datatype such as :class:`.AssociationProxy`.  The Declarative runtime
would erroneously try to interpret this annotation as needing to be
:class:`.Mapped` and raise an error.

Fixed typing issue where using the :class:`.AssociationProxy` return type
from a :class:`_orm.declared_attr` function was disallowed.

Fixes: #9957
Change-Id: I797c5bbdb3d1e81a04ed21c6558ec349b970476f
2023-06-15 10:38:12 -04:00
Jack Wotherspoon dcd938c68e feat: add async_creator argument to create_async_engine
Added new :paramref:`_asyncio.create_async_engine.async_creator` parameter
to :func:`.create_async_engine`, which accomplishes the same purpose as the
:paramref:`.create_engine.creator` parameter of :func:`.create_engine`.
This is a no-argument callable that provides a new asyncio connection,
using the asyncio database driver directly. The
:func:`.create_async_engine` function will wrap the driver-level connection
in the appropriate structures. Pull request curtesy of Jack Wotherspoon.

Fixes #8215
Closes: #9854
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9854
Pull-request-sha: 537073e71e

Change-Id: I184c59ee68436e910464b717f2cbb7e314c1c2cc
2023-06-09 11:21:40 -04:00
Federico Caselli 058c230cea Update black to v23.3.0 and flake8 to v6
This change could be added to .git-blame-ignore-revs

Change-Id: I7ba10052b26bc3c178d23fb50a1123d0aae965ca
2023-05-30 21:44:26 +02:00
Mike Bayer f1f6b296c5 add reflection arguments, engine/conn bind to DeferredReflection.prepare
Improved :meth:`.DeferredReflection.prepare` to accept arbitrary ``**kw``
arguments that are passed to :meth:`_schema.MetaData.reflect`, allowing use
cases such as reflection of views as well as dialect-specific arguments to
be passed. Additionally, modernized the
:paramref:`.DeferredReflection.prepare.bind` argument so that either an
:class:`.Engine` or :class:`.Connection` are accepted as the "bind"
argument.

Fixes: #9828
Change-Id: Ie93cd1147611a92f07d05df8a39052f61ee692f2
2023-05-24 00:13:13 -04:00
mike bayer 4f52073370 Merge "add full parameter types for ORM with_for_update" into main 2023-05-10 20:15:15 +00:00
Mike Bayer 189039b9d3 add full parameter types for ORM with_for_update
Fixed typing for the :paramref:`_orm.Session.get.with_for_update` parameter
of :meth:`_orm.Session.get` and :meth:`_orm.Session.refresh` (as well as
corresponding methods on :class:`_asyncio.AsyncSession`) to accept boolean
``True`` and all other argument forms accepted by the parameter at runtime.

Fixes: #9762
Change-Id: Ied4d37a269906b3d9be5ab7d31a2fa863360cced
2023-05-10 15:24:11 -04:00
mike bayer bce61160a9 Merge "fix test suite warnings" into main 2023-05-10 15:11:06 +00:00
Mike Bayer 60b3119831 fix test suite warnings
fix a handful of warnings that were emitting but not raising,
usually because they were inside an "expect_warnings" block.

modify "expect_warnings" to always use "raise_on_any_unexpected"
behavior; remove this parameter.

Fixed issue in semi-private ``await_only()`` and ``await_fallback()``
concurrency functions where the given awaitable would remain un-awaited if
the function threw a ``GreenletError``, which could cause "was not awaited"
warnings later on if the program continued. In this case, the given
awaitable is now cancelled before the exception is thrown.

Change-Id: I33668c5e8c670454a3d879e559096fb873b57244
2023-05-09 20:23:48 -04:00
Mike Bayer 8ee129d988 guard against duplicate mutable event listeners
Fixed issue in :class:`_mutable.Mutable` where event registration for ORM
mapped attributes would be called repeatedly for mapped inheritance
subclasses, leading to duplicate events being invoked in inheritance
hierarchies.

Fixes: #9676
Change-Id: I91289141d7a5f5c86a9033596735ed6eba7071b0
2023-05-09 16:39:31 -04:00
Mike Bayer b3216486c4 add AsyncAttrs
Added a new helper mixin :class:`_asyncio.AsyncAttrs` that seeks to improve
the use of lazy-loader and other expired or deferred ORM attributes with
asyncio, providing a simple attribute accessor that provides an ``await``
interface to any ORM attribute, whether or not it needs to emit SQL.

Change-Id: I1427b288dc28319c854372643066c491b9ee8dc0
References: #9731
2023-05-08 11:50:03 -04:00