Mike Bayer [Thu, 11 Jan 2024 03:31:59 +0000 (22:31 -0500)]
catch OSError (base of ConnectionError) and asyncpg errors for terminate
Fixed regression in the asyncpg dialect caused by :ticket:`10717` in
release 2.0.24 where the change that now attempts to gracefully close the
asyncpg connection before terminating would not fall back to
``terminate()`` for other potential connection-related exceptions other
than a timeout error, not taking into account cases where the graceful
``.close()`` attempt fails for other reasons such as connection errors.
Mike Bayer [Mon, 8 Jan 2024 14:15:17 +0000 (09:15 -0500)]
DBAPIConnection can be None for checkin event
Fixed the type signature for the :meth:`.PoolEvents.checkin` event to
indicate that the given :class:`.DBAPIConnection` argument may be ``None``
in the case where the connection has been invalidated.
Mike Bayer [Tue, 2 Jan 2024 16:16:13 +0000 (11:16 -0500)]
refactor any_ / all_
Improved compilation of :func:`_sql.any_` / :func:`_sql.all_` in the
context of a negation of boolean comparison, will now render ``NOT (expr)``
rather than reversing the equality operator to not equals, allowing
finer-grained control of negations for these non-typical operators.
Federico Caselli [Thu, 21 Dec 2023 22:41:56 +0000 (23:41 +0100)]
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.
Mike Bayer [Tue, 2 Jan 2024 16:36:20 +0000 (11:36 -0500)]
force uselist=False for all collection class not present
Fixed issue where ORM Annotated Declarative would mis-interpret the left
hand side of a relationship without any collection specified as
uselist=True if the left type were given as a class and not a string,
without using future-style annotations.
jonathan vanasco [Fri, 24 Sep 2021 21:48:09 +0000 (17:48 -0400)]
add new notes on viewonly section
Updated join_conditions documentation to explain the limits of mutation
tracking on advanced relationships and illustrate potential ways to
remedy the situation.
Instead of simply writing a note, the (functional) code from the original
issue was turned into a tutorial that explains the various approaches.
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()``.
Mike Bayer [Mon, 1 Jan 2024 17:49:10 +0000 (12:49 -0500)]
add a generic argument to _HasClauseElement
Further enhancements to pep-484 typing to allow SQL functions from
:attr:`_sql.func` derived elements to work more effectively with ORM-mapped
attributes.
Mike Bayer [Thu, 28 Dec 2023 21:02:48 +0000 (16:02 -0500)]
pop prefetch values from committed_state when they are available
Fixed issue where when making use of the
:paramref:`_orm.relationship.post_update` feature at the same time as using
a mapper version_id_col could lead to a situation where the second UPDATE
statement emitted by the post-update feature would fail to make use of the
correct version identifier, assuming an UPDATE was already emitted in that
flush which had already bumped the version counter.
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.
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_()``.
Mike Bayer [Wed, 20 Dec 2023 15:56:18 +0000 (10:56 -0500)]
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).
Mike Bayer [Tue, 19 Dec 2023 14:00:03 +0000 (09:00 -0500)]
ensure Bundle / DML RETURNING has test support, full impl
Ensured the use case of :class:`.Bundle` objects used in the
``returning()`` portion of ORM-enabled INSERT, UPDATE and DELETE statements
is tested and works fully. This was never explicitly implemented or
tested previously and did not work correctly in the 1.4 series; in the 2.0
series, ORM UPDATE/DELETE with WHERE criteria was missing an implementation
method preventing :class:`.Bundle` objects from working.
Mike Bayer [Tue, 12 Dec 2023 19:57:38 +0000 (14:57 -0500)]
copy stack related elements to str compiler
Fixed issue in stringify for SQL elements, where a specific dialect is not
passed, where a dialect-specific element such as the PostgreSQL "on
conflict do update" construct is encountered and then fails to provide for
a stringify dialect with the appropriate state to render the construct,
leading to internal errors.
Fixed issue where stringifying or compiling a :class:`.CTE` that was
against a DML construct such as an :func:`_sql.insert` construct would fail
to stringify, due to a mis-detection that the statement overall is an
INSERT, leading to internal errors.
Mike Bayer [Mon, 11 Dec 2023 15:55:25 +0000 (10:55 -0500)]
raise ImportError when greenlet not installed
This is the runtime raise when an async concurrency function
is called. in 2.0 this raises ValueError, however here we've
standardized on raising ``ImportError`.
continuing for #10747, add a test asserting we dont get an
endless loop and get a clean ImportError instead when greenlet not
installed and async functions are used.
Mike Bayer [Sat, 9 Dec 2023 15:43:37 +0000 (10:43 -0500)]
ensure test suite runs w/o greenlet
This is a reopen of #6136 essentially that repaired the
test suite to run without greenlet but now this has regressed.
add a tox target that explicitly uninstalls greenlet, will
add to CI.
This also changes 2.0 in that the full tox target will
omit dbdrivers that require greenlet.
Mike Bayer [Wed, 6 Dec 2023 19:10:28 +0000 (14:10 -0500)]
Replace custom URL-encoding method with quote
Fixed URL-encoding of the username and password components of
:class:`.engine.URL` objects when converting them to string using the
:meth:`_engine.URL.render_as_string` method, by using Python standard
library ``urllib.parse.quote`` while allowing for plus signs and spaces to
remain unchanged as supported by SQLAlchemy's non-standard URL parsing,
rather than the legacy home-grown routine from many years ago. Pull request
courtesy of Xavier NUNN.
Michael Oliver [Tue, 5 Dec 2023 22:24:17 +0000 (17:24 -0500)]
Forward `**kw` in `__init_subclass__()` to super
Modified the ``__init_subclass__()`` method used by
:class:`_orm.MappedAsDataclass`, :class:`_orm.DeclarativeBase`` and
:class:`_orm.DeclarativeBaseNoMeta` to accept arbitrary ``**kw`` and to
propagate them to the ``super()`` call, allowing greater flexibility in
arranging custom superclasses and mixins which make use of
``__init_subclass__()`` keyword arguments. Pull request courtesy Michael
Oliver.
eXenon [Mon, 4 Dec 2023 17:39:25 +0000 (12:39 -0500)]
Replace custom URL-encoding method with quote_plus
Fixed URL-encoding of the username and password components of
:class:`.engine.URL` objects when converting them to string using the
:meth:`_engine.URL.render_as_string` method, by using Python standard
library ``urllib.parse.quote_plus``, rather than the legacy home-grown
routine from many years ago. Pull request courtesy of Xavier NUNN.
> A [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime) object `d` is aware if both of the following hold:
>
> `d.tzinfo is not None`
>
> `d.tzinfo.utcoffset(d)` does not return `None`
>
> Otherwise, `d` is naive.
Federico Caselli [Thu, 30 Nov 2023 21:45:36 +0000 (22:45 +0100)]
Remove legacy signatures from session events
Removed legacy signatures dating back to 0.9 release from the
:meth:`_orm.SessionEvents.after_bulk_update` and
:meth:`_orm.SessionEvents.after_bulk_delete`.
Mike Bayer [Thu, 30 Nov 2023 14:11:25 +0000 (09:11 -0500)]
try to gracefully close even in terminate
Adjusted the asyncpg dialect such that when the ``terminate()`` method is
used to discard an invalidated connection, the dialect will first attempt
to gracefully close the conneciton using ``.close()`` with a timeout, if
the operation is proceeding within an async event loop context only. This
allows the asyncpg driver to attend to finalizing a ``TimeoutError``
including being able to close a long-running query server side, which
otherwise can keep running after the program has exited.
Federico Caselli [Wed, 16 Aug 2023 20:18:10 +0000 (22:18 +0200)]
Change Sequence and Identity oracle only kwargs.
Deprecate Oracle only parameters :paramref:`_schema.Sequence.order`,
paramref:`_schema.Identity.order` and :paramref:`_schema.Identity.on_null`.
They should be configured using the dialect kwargs ``oracle_order`` and
oracle_on_null``.
Mike Bayer [Sun, 26 Nov 2023 15:02:47 +0000 (10:02 -0500)]
add MARS connection for aioodbc
on jenkins main we are getting a lot of connection busy with
other results, which we assume is due to the thread-pool based approach
of aioodbc not being very solid.
not clear why the name of the parameter is different in those two
articles. using a totally made up parameter doesn't raise any error,
so it's not clear if this works at all.
Martijn Pieters [Sat, 18 Nov 2023 21:36:08 +0000 (16:36 -0500)]
Add type annotations for Function.filter
This includes all methods / properties on the returned FunctionFilter
object.
This contributes towards #6810
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, 24 Nov 2023 20:20:31 +0000 (15:20 -0500)]
fully type functions.py
Completed pep-484 typing for the ``sqlalchemy.sql.functions`` module.
:func:`_sql.select` constructs made against ``func`` elements should now
have filled-in return types.
Gerald Venzl [Thu, 23 Nov 2023 19:42:52 +0000 (14:42 -0500)]
Upgrade to Oracle Database 23c Free
### Description
This PR updates the unittest ReadMe and `setup.cfg` to use Oracle Database Free, the successor to Oracle Database XE.
### Checklist
This pull request is:
- [ ] 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.
François Voron [Thu, 23 Nov 2023 15:53:07 +0000 (10:53 -0500)]
docs: fix type annotation in Self-Referential Many-to-Many Relationsh…
A type annotation was wrong in the [Self-Referential Many-to-Many Relationship](https://docs.sqlalchemy.org/en/20/orm/join_conditions.html#self-referential-many-to-many-relationship) code example.
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
The type annotation was `right_nodes: Mapped[List["None"]]`. I changed it to `Node` since we refer to the ORM class we're looking at.
### 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.
Jan Vollmer [Wed, 22 Nov 2023 18:16:27 +0000 (13:16 -0500)]
add local column to dependency rule error message
Improved the error message produced when the unit of work process sets the
value of a primary key column to NULL due to a related object with a
dependency rule on that column being deleted, to include not just the
destination object and column name but also the source column from which
the NULL value is originating. Pull request courtesy Jan Vollmer.
Mike Bayer [Sat, 18 Nov 2023 15:22:19 +0000 (10:22 -0500)]
update all errors / warnings in schema to use f strings
Fixed issue where error reporting for unexpected schema item when creating
objects like :class:`_schema.Table` would incorrectly handle an argument
that was itself passed as a tuple, leading to a formatting error. The
error message has been modernized to use f-strings.
this change necessitated an update to flake8 as version 5 was
mis-interpreting f-strings that had semicolons in them.
Black is also unable to format some of these f-strings which had
to be broken out, unclear if there is a newer Black available.
Mike Bayer [Mon, 13 Nov 2023 20:52:43 +0000 (15:52 -0500)]
adapt all asyncio dialects to asyncio connector
Adapted all asyncio dialects, including aiosqlite, aiomysql, asyncmy,
psycopg, asyncpg to use the generic asyncio connection adapter first added
in :ticket:`6521` for the aioodbc DBAPI, allowing these dialects to take
advantage of a common framework.
Update type annotation for DBAPI Cursor's executemany()
### Description
As per https://groups.google.com/g/sqlalchemy/c/DkyffAgDmwM, fixes an issue with the DBAPI cursor's executemany() type signature.
### 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.
Added an initialize step to the import of
``sqlalchemy.ext.asyncio`` so that ``greenlet`` will
be imported only when the asyncio extension is first imported.
Alternatively, the ``greenlet`` library is still imported lazily on
first use to support use case that don't make direct use of the
SQLAlchemy asyncio extension.