]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/log
thirdparty/sqlalchemy/sqlalchemy.git
2 years agoAdd separate version notes for scalars
Grey Li [Sun, 26 Feb 2023 10:56:37 +0000 (05:56 -0500)] 
Add separate version notes for scalars

Add separate 1.4.24 and 1.4.26 version notes for the .scalars method;
this covers Session, scoped_session, AsyncSession, async_scoped_session
as the "scoped" versions did not have the method added until 1.4.26
as part of :ticket:`7103`.

Also indicate scoped_session as ``sqlalchemy.orm.scoped_session`` in
docs rather than ``sqlalchemy.orm.scoping.scoped_session``.  This is
also happening in I77da54891860095edcb1f0625ead99fee89bd76f separately,
as both changesets refer to scoped_session without using ".scoping".

References: #7103
Closes: #9371
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9371
Pull-request-sha: 61132230cc6e897ab61beff25d98b19a4c0aefd0

Change-Id: I84c8b1aad752db124cfee6bc8516f6eed7ba2faf

2 years agoupdate case statement to v2 syntax
Federico Caselli [Fri, 24 Feb 2023 20:32:46 +0000 (21:32 +0100)] 
update case statement to v2 syntax

Change-Id: If278ea170e0a17b1e8ace2d470fb2fbdb7a6e9c1
References: #9370
References: #9365

2 years agouse Column for legacy dataclasses mapping
Mike Bayer [Fri, 24 Feb 2023 04:52:31 +0000 (23:52 -0500)] 
use Column for legacy dataclasses mapping

Fixes: #9361
Change-Id: I9c433960664aa2b75cd03925d9dcf2e1ff27d8ce

2 years agoadd notes to all mapper flush events that these are only for flush
Mike Bayer [Tue, 21 Feb 2023 16:00:03 +0000 (11:00 -0500)] 
add notes to all mapper flush events that these are only for flush

Fixes: #9339
Change-Id: I44542166417776733245e2ba39cd5de89b6d748b

2 years agoFix the docstring of AppenerQuery.append() (#9336)
Grey Li [Mon, 20 Feb 2023 20:05:09 +0000 (04:05 +0800)] 
Fix the docstring of AppenerQuery.append() (#9336)

2 years agoFix a syntax error in `AsyncConnection.stream_scalars()` example. (#9334)
Vytautas Liuolia [Sun, 19 Feb 2023 16:47:33 +0000 (17:47 +0100)] 
Fix a syntax error in `AsyncConnection.stream_scalars()` example. (#9334)

2 years agoUpdate dialect documentation about CrateDB (#9322)
Andreas Motl [Sun, 19 Feb 2023 16:47:02 +0000 (08:47 -0800)] 
Update dialect documentation about CrateDB (#9322)

The `crate-0.30.0` package offers compatibility with SQLAlchemy 2.0.

2 years agoFix grammatical error in intro.rst (#9316)
Maxwell D. Dorliea [Sun, 19 Feb 2023 16:46:42 +0000 (16:46 +0000)] 
Fix grammatical error in intro.rst (#9316)

2 years agoconsider column.name directly when evaluating use_existing_column
Mike Bayer [Sat, 18 Feb 2023 14:10:20 +0000 (09:10 -0500)] 
consider column.name directly when evaluating use_existing_column

Fixed issue where new :paramref:`_orm.mapped_column.use_existing_column`
feature would not work if the two same-named columns were mapped under
attribute names that were differently-named from the explicit name given to
the column itself. The attribute names can now be differently named when
using this parameter.

Fixes: #9332
Change-Id: I43716b8ca2b089e54a2b078db28b6c4770468bdd

2 years agofix sphinx command got stuck in output
Mike Bayer [Fri, 17 Feb 2023 18:00:48 +0000 (13:00 -0500)] 
fix sphinx command got stuck in output

Change-Id: Idf68d2c5e40a3b072ad1cd479638f9eb364ba15f

2 years agomore edits
Mike Bayer [Fri, 17 Feb 2023 16:25:16 +0000 (11:25 -0500)] 
more edits

I can only see issues in the docs when they're live on the
site, sorry

Change-Id: I948b7c8e37657ca85d02843211cbfdb03aa5da75

2 years agotypo, captions
Mike Bayer [Fri, 17 Feb 2023 16:23:41 +0000 (11:23 -0500)] 
typo, captions

Change-Id: I547e66b60f5a7b2901a76ebc59469bce018e05ff

2 years agoVersion 2.0.5 placeholder
Mike Bayer [Fri, 17 Feb 2023 16:01:43 +0000 (11:01 -0500)] 
Version 2.0.5 placeholder

2 years ago- 2.0.4 rel_2_0_4
Mike Bayer [Fri, 17 Feb 2023 15:47:40 +0000 (10:47 -0500)] 
- 2.0.4

2 years agochangelog updates
Mike Bayer [Fri, 17 Feb 2023 15:47:00 +0000 (10:47 -0500)] 
changelog updates

Change-Id: Id28c5ae101cf462609740a698a1b188cce01bc5a

2 years agorework hybrid docs further
Mike Bayer [Fri, 17 Feb 2023 15:24:32 +0000 (10:24 -0500)] 
rework hybrid docs further

we have a very complicated story to tell and we need to
keep it within "reference doc" mode as much as we can

Change-Id: I873b7d95aea7b5a1d04de0c78a4e88651c908b35

2 years agoAllow custom sorting of column in the ORM.
Federico Caselli [Thu, 16 Feb 2023 20:52:18 +0000 (21:52 +0100)] 
Allow custom sorting of column in the ORM.

To accommodate a change in column ordering used by ORM Declarative in
SQLAlchemy 2.0, a new parameter :paramref:`_orm.mapped_column.sort_order`
has been added that can be used to control the order of the columns defined
in the table by the ORM, for common use cases such as mixins with primary
key columns that should appear first in tables. The change notes at
:ref:`change_9297` illustrate the default change in ordering behavior
(which is part of all SQLAlchemy 2.0 releases) as well as use of the
:paramref:`_orm.mapped_column.sort_order` to control column ordering when
using mixins and multiple classes (new in 2.0.4).

Fixes: #9297
Change-Id: Ic7163d64efdc0eccb53d6ae0dd89ec83427fb675

2 years agoMerge "modernize hybrids and apply typing" into main
mike bayer [Fri, 17 Feb 2023 00:20:00 +0000 (00:20 +0000)] 
Merge "modernize hybrids and apply typing" into main

2 years agomodernize hybrids and apply typing
Mike Bayer [Thu, 16 Feb 2023 14:39:07 +0000 (09:39 -0500)] 
modernize hybrids and apply typing

Improved the typing support for the :ref:`hybrids_toplevel`
extension, updated all documentation to use ORM Annotated Declarative
mappings, and added a new modifier called :attr:`.hybrid_property.inplace`.
This modifier provides a way to alter the state of a :class:`.hybrid_property`
**in place**, which is essentially what very early versions of hybrids
did, before SQLAlchemy version 1.2.0 :ticket:`3912` changed this to
remove in-place mutation.  This in-place mutation is now restored on an
**opt-in** basis to allow a single hybrid to have multiple methods
set up, without the need to name all the methods the same and without the
need to carefully "chain" differently-named methods in order to maintain
the composition.  Typing tools such as Mypy and Pyright do not allow
same-named methods on a class, so with this change a succinct method
of setting up hybrids with typing support is restored.

Change-Id: Iea88025f023428f9f006846d09fbb4be391f5ebb
References: #9321

2 years agoMerge "Fix coercion issue for tuple bindparams" into main
mike bayer [Thu, 16 Feb 2023 19:57:50 +0000 (19:57 +0000)] 
Merge "Fix coercion issue for tuple bindparams" into main

2 years agoFix coercion issue for tuple bindparams
mike bayer [Wed, 15 Feb 2023 22:20:06 +0000 (23:20 +0100)] 
Fix coercion issue for tuple bindparams

Fixed issue where element types of a tuple value would be hardcoded to take
on the types from a compared-to tuple, when the comparison were using the
:meth:`.ColumnOperators.in_` operator. This was inconsistent with the usual
way that types are determined for a binary expression, which is that the
actual element type on the right side is considered first before applying
the left-hand-side type.

Fixes: #9313
Change-Id: Ia8874c09682a6512fcf4084cf14481024959c461

2 years agoMerge "rename EvaluatorCompiler to _EvaluatorCompiler" into main
mike bayer [Thu, 16 Feb 2023 02:38:47 +0000 (02:38 +0000)] 
Merge "rename EvaluatorCompiler to _EvaluatorCompiler" into main

2 years agoMerge "add dataclasses callable and apply annotations more strictly" into main
mike bayer [Thu, 16 Feb 2023 02:37:52 +0000 (02:37 +0000)] 
Merge "add dataclasses callable and apply annotations more strictly" into main

2 years agoimmediateload lazy relationships named in refresh.attribute_names
Mike Bayer [Mon, 13 Feb 2023 16:17:09 +0000 (11:17 -0500)] 
immediateload lazy relationships named in refresh.attribute_names

The :meth:`_orm.Session.refresh` method will now immediately load a
relationship-bound attribute that is explicitly named within the
:paramref:`_orm.Session.refresh.attribute_names` collection even if it is
currently linked to the "select" loader, which normally is a "lazy" loader
that does not fire off during a refresh. The "lazy loader" strategy will
now detect that the operation is specifically a user-initiated
:meth:`_orm.Session.refresh` operation which named this attribute
explicitly, and will then call upon the "immediateload" strategy to
actually emit SQL to load the attribute. This should be helpful in
particular for some asyncio situations where the loading of an unloaded
lazy-loaded attribute must be forced, without using the actual lazy-loading
attribute pattern not supported in asyncio.

Fixes: #9298
Change-Id: I9b50f339bdf06cdb2ec98f8e5efca2b690895dd7

2 years agoadd dataclasses callable and apply annotations more strictly
Mike Bayer [Fri, 10 Feb 2023 21:06:23 +0000 (16:06 -0500)] 
add dataclasses callable and apply annotations more strictly

Added new parameter ``dataclasses_callable`` to both the
:class:`_orm.MappedAsDataclass` class as well as the
:meth:`_orm.registry.mapped_as_dataclass` method which allows an
alternative callable to Python ``dataclasses.dataclass`` to be used in
order to produce dataclasses. The use case here is to drop in Pydantic's
dataclass function instead. Adjustments have been made to the mixin support
added for :ticket:`9179` in version 2.0.1 so that the ``__annotations__``
collection of the mixin is rewritten to not include the
:class:`_orm.Mapped` container, in the same way as occurs with mapped
classes, so that the Pydantic dataclasses constructor is not exposed to
unknown types.

Fixes: #9266
Change-Id: Ia0fab6f20b93a5cb853799dcf1b70a0386837c14

2 years agorename EvaluatorCompiler to _EvaluatorCompiler
Mike Bayer [Mon, 13 Feb 2023 17:31:44 +0000 (12:31 -0500)] 
rename EvaluatorCompiler to _EvaluatorCompiler

This is a private class, mark as such as some users
may have used this class directly in end-user code.

Change-Id: I2657eff1f9f11b59c0483922ac67d6420a082906
References: #9299

2 years agoprevent float tests from running on asyncmy
Mike Bayer [Wed, 15 Feb 2023 23:28:12 +0000 (18:28 -0500)] 
prevent float tests from running on asyncmy

asyncmy 0.2.7 has had a loss in float precision for even
very low numbers of significant digits.

Change-Id: Iec6d2650943eeaa8e854f21990f6565d73331f8c
References: https://github.com/long2ice/asyncmy/issues/56

2 years agomention mypy>=1 is required to type check the library
Federico Caselli [Wed, 15 Feb 2023 19:35:41 +0000 (20:35 +0100)] 
mention mypy>=1 is required to type check the library

Change-Id: Ie514c76b4f6b3241bba5083219a3eae19c2b7aae

2 years agoMerge "Improve ``oracledb`` thick mode flag." into main
mike bayer [Wed, 15 Feb 2023 18:21:31 +0000 (18:21 +0000)] 
Merge "Improve ``oracledb`` thick mode flag." into main

2 years agoMerge "Add ``Table.autoincrement_column``" into main
mike bayer [Wed, 15 Feb 2023 18:19:18 +0000 (18:19 +0000)] 
Merge "Add ``Table.autoincrement_column``" into main

2 years agoMerge "test dataclasses.KW_ONLY" into main
mike bayer [Wed, 15 Feb 2023 14:20:42 +0000 (14:20 +0000)] 
Merge "test dataclasses.KW_ONLY" into main

2 years agoImprove ``oracledb`` thick mode flag.
Federico Caselli [Mon, 13 Feb 2023 21:35:09 +0000 (22:35 +0100)] 
Improve ``oracledb`` thick mode flag.

Adjusted ``oracledb`` thick mode flag to make ``thick_mode=False`` not
enable thick mode. Previously only ``None`` was accepted as off value.

Fixes: #9295
Change-Id: I1a8397c19d065dfc2dda597e719922fc8d31acb1

2 years agofix typo in whatsnew (#9303)
Andrei Pozolotin [Tue, 14 Feb 2023 20:34:18 +0000 (14:34 -0600)] 
fix typo in whatsnew (#9303)

see #9294

2 years agoAdd ``Table.autoincrement_column``
Federico Caselli [Fri, 10 Feb 2023 20:37:20 +0000 (21:37 +0100)] 
Add ``Table.autoincrement_column``

Added public property :attr:`_sql.Table.autoincrement_column` that
returns the column identified as autoincrementing in the column.

Fixes: #9277
Change-Id: If60d6f92e0df94f57d00ff6d89d285c61b02f5a4

2 years agofix typo "Annotation" -> "Annotated" and use typing_extensions
Mike Bayer [Tue, 14 Feb 2023 16:13:43 +0000 (11:13 -0500)] 
fix typo "Annotation" -> "Annotated" and use typing_extensions

Fixes: #9305
Change-Id: I9f0ab24f609f6f557b5780209a85f0abe82b363e

2 years agotest dataclasses.KW_ONLY
Mike Bayer [Tue, 14 Feb 2023 14:09:15 +0000 (09:09 -0500)] 
test dataclasses.KW_ONLY

had no test support for this, seems to work.  gets
grabbed in annotations and applied correctly.

Change-Id: I2cd7ad7b376f38f945d2007b316a1316271f9a0f

2 years agofix documentation formatting
Federico Caselli [Mon, 13 Feb 2023 19:16:45 +0000 (20:16 +0100)] 
fix documentation formatting

Change-Id: I3307e1844237b58486dcce334eab80689e116bb8

2 years agocompletely lift-and-copy and_ / or_ documentation
Mike Bayer [Mon, 13 Feb 2023 17:23:28 +0000 (12:23 -0500)] 
completely lift-and-copy and_ / or_ documentation

Sphinx refuses to write the correct docstring for these without
placing a completely literal string with no interpolation of
any kind.   Current site has blank for these.

Change-Id: Ie19a0b89d05b45509708585e6efca1a35f30adb5

2 years agonote column ordering change, indicate recipe to control ordering
Mike Bayer [Mon, 13 Feb 2023 15:08:52 +0000 (10:08 -0500)] 
note column ordering change, indicate recipe to control ordering

Change-Id: I520c18ac8c84923558e2042265943b6340700788
References: #9294

2 years agoFix docs for `case` expression to match new syntax (#9279)
Abdulhaq Emhemmed [Fri, 10 Feb 2023 21:56:30 +0000 (22:56 +0100)] 
Fix docs for `case` expression to match new syntax (#9279)

* Fix docs for `case` expression to match new syntax

Previously (before v1.4), the `whens` arg (when `value` is *not* used) used to be a list of
conditions (a 2 item-tuple of condition + value). From v1.4, these are passed
as positional args and the old syntax is not supported anymore.

* Fix long lines

2 years agoadd requirement, restore test removed in eb0861e8e69f8ce702301c558e552e1aeb2e9eba
Federico Caselli [Fri, 10 Feb 2023 20:06:13 +0000 (21:06 +0100)] 
add requirement, restore test removed in eb0861e8e69f8ce702301c558e552e1aeb2e9eba

Change-Id: I78c12a58eef59ff577a88880a8752151051fd939

2 years agogeneralize adapt_on_names to expect non-named elements
Mike Bayer [Fri, 10 Feb 2023 13:39:21 +0000 (08:39 -0500)] 
generalize adapt_on_names to expect non-named elements

The fix in #9217 opened up adapt_on_names to more kinds of
expressions than it was prepared for; adjust that logic
and also refine in the ORM where we are using it, as we
dont need it (yet) for the DML RETURNING use case.

Fixed regression introduced in version 2.0.2 due to :ticket:`9217` where
using DML RETURNING statements, as well as
:meth:`_sql.Select.from_statement` constructs as was "fixed" in
:ticket:`9217`, in conjunction with ORM mapped classes that used
expressions such as with :func:`_orm.column_property`, would lead to an
internal error within Core where it would attempt to match the expression
by name. The fix repairs the Core issue, and also adjusts the fix in
:ticket:`9217` to not take effect for the DML RETURNING use case, where it
adds unnecessary overhead.

Fixes: #9273
Change-Id: Ie0344efb12ff7df48f21e71e62dc598c76a6a0de

2 years agoVersion 2.0.4 placeholder
Mike Bayer [Fri, 10 Feb 2023 00:15:26 +0000 (19:15 -0500)] 
Version 2.0.4 placeholder

2 years ago- 2.0.3 rel_2_0_3
Mike Bayer [Thu, 9 Feb 2023 23:01:33 +0000 (18:01 -0500)] 
- 2.0.3

2 years agoapply self_group to all elements of multi-expression
Mike Bayer [Thu, 9 Feb 2023 20:36:38 +0000 (15:36 -0500)] 
apply self_group to all elements of multi-expression

Fixed critical regression in SQL expression formulation in the 2.0 series
due to :ticket:`7744` which improved support for SQL expressions that
contained many elements against the same operator repeatedly; parenthesis
grouping would be lost with expression elements beyond the first two
elements.

Fixes: #9271
Change-Id: Ib6ed5b71efe0f6816dab75bda622297fc89e3b49

2 years agopin sphinx-copybutton and change config
Mike Bayer [Thu, 9 Feb 2023 17:05:47 +0000 (12:05 -0500)] 
pin sphinx-copybutton and change config

sphinx-copybutton introduced a new feature
in 0.5.1 which includes a default configuration
that breaks the regexp prompt matching scheme.

set copybutton_exclude to not include ".gp" as that's the class
where we exactly look for the prompts we are matching.
While we're there, use this new feature to exclude our sql
styles, even though this is not strictly necessary in our case.

pin sphinx-copybutton at 0.5.1 to avoid future problems.

Change-Id: I8eaeab13995c032b9ee3afd1f08dae5929009d45
References: https://github.com/executablebooks/sphinx-copybutton/issues/185

2 years agoadd test for #9268
Mike Bayer [Wed, 8 Feb 2023 23:49:43 +0000 (18:49 -0500)] 
add test for #9268

Change-Id: I3075472de51b9d0d429f7f6204093f3e481fc121

2 years agotyping: fix hybrid property setter (#9269)
Mehdi ABAAKOUK [Wed, 8 Feb 2023 22:48:16 +0000 (23:48 +0100)] 
typing: fix hybrid property setter (#9269)

Fixes #9268

2 years agoMerge "Remove `typing.Self` workaround" into main
mike bayer [Wed, 8 Feb 2023 18:18:16 +0000 (18:18 +0000)] 
Merge "Remove `typing.Self` workaround" into main

2 years agoRemove `typing.Self` workaround
Yurii Karabas [Tue, 7 Feb 2023 22:43:26 +0000 (17:43 -0500)] 
Remove `typing.Self` workaround

Remove ``typing.Self`` workaround, now using :pep:`673` for most methods
that return ``Self``. Pull request courtesy Yurii Karabas.

Fixes: #9254
Closes: #9255
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9255
Pull-request-sha: 2947df8ada79f5c3afe9c838e65993302199c2f7

Change-Id: Ic32015ad52e95a61f3913d43ea436aa9402804df

2 years agoMerge "use Dict[], not dict[] in mypy test" into main
Federico Caselli [Wed, 8 Feb 2023 07:54:24 +0000 (07:54 +0000)] 
Merge "use Dict[], not dict[] in mypy test" into main

2 years agoimprove github test workflows
Federico Caselli [Tue, 7 Feb 2023 21:32:47 +0000 (22:32 +0100)] 
improve github test workflows

Change-Id: Id0c8eb9c574c44365f6b8bca93b562dea5c8f9eb

2 years agouse Dict[], not dict[] in mypy test
Mike Bayer [Tue, 7 Feb 2023 21:28:36 +0000 (16:28 -0500)] 
use Dict[], not dict[] in mypy test

Fixes: #9253
Change-Id: I8a96fd165c5306566ab02aab25b30558530c9751

2 years agomake this link optional
Mike Bayer [Tue, 7 Feb 2023 20:25:46 +0000 (15:25 -0500)] 
make this link optional

it's too much to require it

Change-Id: I567ba7423a37924666aa821521fad7fe3764e506

2 years agomore edits
Mike Bayer [Tue, 7 Feb 2023 18:38:56 +0000 (13:38 -0500)] 
more edits

looking good

Change-Id: Ifa9a900ced376a75d43e5720567324fa0b3a6336

2 years agoissue template edits
Mike Bayer [Tue, 7 Feb 2023 18:30:30 +0000 (13:30 -0500)] 
issue template edits

Change-Id: I8a19db15ac839968bc6f46bbc36dc16b757426ab

2 years agoanother template edit
Mike Bayer [Tue, 7 Feb 2023 18:29:02 +0000 (13:29 -0500)] 
another template edit

Change-Id: I611eefbb166ab10d05011f39df2b4531a1f59968

2 years agoissue template updates
Mike Bayer [Tue, 7 Feb 2023 18:21:37 +0000 (13:21 -0500)] 
issue template updates

forgive me, I'm just live editing, will test immediately

Change-Id: I404edac799222aea615886c5e821d7433b8f2e7a

2 years agoVersion 2.0.3 placeholder
Mike Bayer [Tue, 7 Feb 2023 00:04:32 +0000 (19:04 -0500)] 
Version 2.0.3 placeholder

2 years ago- 2.0.2 rel_2_0_2
Mike Bayer [Mon, 6 Feb 2023 23:55:27 +0000 (18:55 -0500)] 
- 2.0.2

2 years agoMerge "do not return asyncio connections to the pool under gc" into main
mike bayer [Mon, 6 Feb 2023 23:52:23 +0000 (23:52 +0000)] 
Merge "do not return asyncio connections to the pool under gc" into main

2 years agoMerge "add error code 1049 for mysql has_table" into main
Federico Caselli [Mon, 6 Feb 2023 21:56:18 +0000 (21:56 +0000)] 
Merge "add error code 1049 for mysql has_table" into main

2 years agochangelog fixup
Mike Bayer [Mon, 6 Feb 2023 21:25:15 +0000 (16:25 -0500)] 
changelog fixup

re-classify the large amount of recent issues involving
declarative under "orm declarative" and reword one of the
issue notes.

Change-Id: Id3a861b235573bf048a9ee4d38faeaade8a9dbdd

2 years agoMerge "Dedicated bitwise operators" into main
mike bayer [Mon, 6 Feb 2023 21:11:46 +0000 (21:11 +0000)] 
Merge "Dedicated bitwise operators" into main

2 years agoMerge "use mysql 8 syntax for ON DUPLICATE KEY UPDATE" into main
mike bayer [Mon, 6 Feb 2023 21:11:05 +0000 (21:11 +0000)] 
Merge "use mysql 8 syntax for ON DUPLICATE KEY UPDATE" into main

2 years agodo not return asyncio connections to the pool under gc
Mike Bayer [Sun, 5 Feb 2023 19:12:50 +0000 (14:12 -0500)] 
do not return asyncio connections to the pool under gc

Repaired a regression caused by the fix for :ticket:`8419` which caused
asyncpg connections to be reset (i.e. transaction ``rollback()`` called)
and returned to the pool normally in the case that the connection were not
explicitly returned to the connection pool and was instead being
intercepted by Python garbage collection, which would fail if the garbage
collection operation were being called outside of the asyncio event loop,
leading to a large amount of stack trace activity dumped into logging
and standard output.

The correct behavior is restored, which is that all asyncio connections
that are garbage collected due to not being explicitly returned to the
connection pool are detached from the pool and discarded, along with a
warning, rather than being returned the pool, as they cannot be reliably
reset. In the case of asyncpg connections, the asyncpg-specific
``terminate()`` method will be used to end the connection more gracefully
within this process as opposed to just dropping it.

This change includes a small behavioral change that is hoped to be useful
for debugging asyncio applications, where the warning that's emitted in the
case of asyncio connections being unexpectedly garbage collected has been
made slightly more aggressive by moving it outside of a ``try/except``
block and into a ``finally:`` block, where it will emit unconditionally
regardless of whether the detach/termination operation succeeded or not. It
will also have the effect that applications or test suites which promote
Python warnings to exceptions will see this as a full exception raise,
whereas previously it was not possible for this warning to actually
propagate as an exception. Applications and test suites which need to
tolerate this warning in the interim should adjust the Python warnings
filter to allow these warnings to not raise.

The behavior for traditional sync connections remains unchanged, that
garbage collected connections continue to be returned to the pool normally
without emitting a warning. This will likely be changed in a future major
release to at least emit a similar warning as is emitted for asyncio
drivers, as it is a usage error for pooled connections to be intercepted by
garbage collection without being properly returned to the pool.

Fixes: #9237
Change-Id: Ib35cfb2e628f2eb2da6d2b65674702556f55603a

2 years agoadd error code 1049 for mysql has_table
Mike Bayer [Mon, 6 Feb 2023 18:54:56 +0000 (13:54 -0500)] 
add error code 1049 for mysql has_table

Fixed regression caused by issue :ticket:`9058` which adjusted the MySQL
dialect's ``has_table()`` to again use "DESCRIBE", where the specific error
code raised by MySQL version 8 when using a non-existent schema name was
unexpected and failed to be interpreted as a boolean result.

Fixed the SQLite dialect's ``has_table()`` function to correctly report
False for queries that include a non-None schema name for a schema that
doesn't exist; previously, a database error was raised.

Fixes: #9251
Change-Id: I5ef9cf0887865c3c521d88bca0ba18954a108241

2 years agoMerge "port history meta to 2.0" into main
mike bayer [Mon, 6 Feb 2023 18:04:58 +0000 (18:04 +0000)] 
Merge "port history meta to 2.0" into main

2 years agoDedicated bitwise operators
jazzthief [Thu, 2 Feb 2023 18:48:13 +0000 (13:48 -0500)] 
Dedicated bitwise operators

Added a full suite of new SQL bitwise operators, for performing
database-side bitwise expressions on appropriate data values such as
integers, bit-strings, and similar. Pull request courtesy Yegor Statkevich.

Fixes: #8780
Closes: #9204
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9204
Pull-request-sha: a4541772a6a784f9161ad78ef84d2ea7a62fa8de

Change-Id: I4c70e80f9548dcc1b4e3dccd71bd59d51d3ed46e

2 years agoMerge "check for superclasses of user defined init" into main
mike bayer [Mon, 6 Feb 2023 17:01:50 +0000 (17:01 +0000)] 
Merge "check for superclasses of user defined init" into main

2 years agoport history meta to 2.0
Mike Bayer [Thu, 2 Feb 2023 19:38:37 +0000 (14:38 -0500)] 
port history meta to 2.0

first change:

Reworked the :ref:`examples_versioned_history` to work with
version 2.0, while at the same time improving the overall working of
this example to use newer APIs, including a newly added hook
:meth:`_orm.MapperEvents.after_mapper_constructed`.

second change:

Added new event hook :meth:`_orm.MapperEvents.after_mapper_constructed`,
which supplies an event hook to take place right as the
:class:`_orm.Mapper` object has been fully constructed, but before the
:meth:`_orm.registry.configure` call has been called. This allows code that
can create additional mappings and table structures based on the initial
configuration of a :class:`_orm.Mapper`, which also integrates within
Declarative configuration. Previously, when using Declarative, where the
:class:`_orm.Mapper` object is created within the class creation process,
there was no documented means of running code at this point.  The change
is to immediately benefit custom mapping schemes such as that
of the :ref:`examples_versioned_history` example, which generate additional
mappers and tables in response to the creation of mapped classes.

third change:

The infrequently used :attr:`_orm.Mapper.iterate_properties` attribute and
:meth:`_orm.Mapper.get_property` method, which are primarily used
internally, no longer implicitly invoke the :meth:`_orm.registry.configure`
process. Public access to these methods is extremely rare and the only
benefit to having :meth:`_orm.registry.configure` would have been allowing
"backref" properties be present in these collections. In order to support
the new :meth:`_orm.MapperEvents.after_mapper_constructed` event, iteration
and access to the internal :class:`_orm.MapperProperty` objects is now
possible without triggering an implicit configure of the mapper itself.

The more-public facing route to iteration of all mapper attributes, the
:attr:`_orm.Mapper.attrs` collection and similar, will still implicitly
invoke the :meth:`_orm.registry.configure` step thus making backref
attributes available.

In all cases, the :meth:`_orm.registry.configure` is always available to
be called directly.

fourth change:

Fixed obscure ORM inheritance issue caused by :ticket:`8705` where some
scenarios of inheriting mappers that indicated groups of columns from the
local table and the inheriting table together under a
:func:`_orm.column_property` would nonetheless warn that properties of the
same name were being combined implicitly.

Fixes: #9220
Fixes: #9232
Change-Id: Id335b8e8071c8ea509c057c389df9dcd2059437d

2 years agouse mysql 8 syntax for ON DUPLICATE KEY UPDATE
Caspar Wylie [Fri, 3 Feb 2023 14:23:26 +0000 (09:23 -0500)] 
use mysql 8 syntax for ON DUPLICATE KEY UPDATE

Added support for MySQL 8's new ``AS <name> ON DUPLICATE KEY`` syntax when
using :meth:`_mysql.Insert.on_duplicate_key_update`, which is required for
newer versions of MySQL 8 as the previous syntax using ``VALUES()`` now
emits a deprecation warning with those versions. Server version detection
is employed to determine if traditional MariaDB / MySQL < 8 ``VALUES()``
syntax should be used, vs. the newer MySQL 8 required syntax. Pull request
courtesy Caspar Wylie.

Fixes: #8626
Closes: #9210
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9210
Pull-request-sha: 1c8dfbf0b4c439d9ca2c194524c47eb7239ee3c5

Change-Id: I42c463837af06bc15b60c534159804193df07f02

2 years agoMerge "use tox extras" into main
mike bayer [Mon, 6 Feb 2023 15:26:54 +0000 (15:26 +0000)] 
Merge "use tox extras" into main

2 years agocheck for superclasses of user defined init
Mike Bayer [Mon, 6 Feb 2023 15:16:26 +0000 (10:16 -0500)] 
check for superclasses of user defined init

Fixed regression caused by the fix for :ticket:`9171`, which itself was
fixing a regression, involving the mechanics of ``__init__()`` on classes
that extend from :class:`_orm.DeclarativeBase`. The change made it such
that ``__init__()`` was applied to the user-defined base if there were no
``__init__()`` method directly on the class. This has been adjusted so that
``__init__()`` is applied only if no other class in the hierarchy of the
user-defined base has an ``__init__()`` method. This again allows
user-defined base classes based on :class:`_orm.DeclarativeBase` to include
mixins that themselves include a custom ``__init__()`` method.

Fixes: #9249
Change-Id: I78f32590ce9ffe245eccb4bd5bd7c884d4e015d5

2 years agoMerge "coerce elements in mapper.primary_key, process in __mapper_args__" into main
mike bayer [Sun, 5 Feb 2023 22:57:05 +0000 (22:57 +0000)] 
Merge "coerce elements in mapper.primary_key, process in __mapper_args__" into main

2 years agoupdate asyncio examples and add notes about writeonly
Mike Bayer [Sun, 5 Feb 2023 21:42:27 +0000 (16:42 -0500)] 
update asyncio examples and add notes about writeonly

Change-Id: I1233eb1a860b915fb265ec8bf177f1a0471cdbd1

2 years agoMerge "Guard against wrong dataclass mapping" into main
Federico Caselli [Sun, 5 Feb 2023 17:18:21 +0000 (17:18 +0000)] 
Merge "Guard against wrong dataclass mapping" into main

2 years agoMerge "disallow ORM instrumented attributes from reaching dataclasses" into main
Federico Caselli [Sun, 5 Feb 2023 17:10:59 +0000 (17:10 +0000)] 
Merge "disallow ORM instrumented attributes from reaching dataclasses" into main

2 years agoMerge "dont add non-server-side cols to returning for versioning" into main
mike bayer [Sun, 5 Feb 2023 16:40:43 +0000 (16:40 +0000)] 
Merge "dont add non-server-side cols to returning for versioning" into main

2 years agoGuard against wrong dataclass mapping
Federico Caselli [Wed, 1 Feb 2023 21:25:03 +0000 (22:25 +0100)] 
Guard against wrong dataclass mapping

Ensure that the decorator style @registry.mapped_as_dataclass and
MappedAsDataclass are not mixed.

Fixes: #9211
Change-Id: I5cd94cae862122e4f627d0d051495b3789cf6de5

2 years agocoerce elements in mapper.primary_key, process in __mapper_args__
Mike Bayer [Sat, 4 Feb 2023 21:35:21 +0000 (16:35 -0500)] 
coerce elements in mapper.primary_key, process in __mapper_args__

Repaired ORM Declarative mappings to allow for the
:paramref:`_orm.Mapper.primary_key` parameter to be specified within
``__mapper_args__`` when using :func:`_orm.mapped_column`. Despite this
usage being directly in the 2.0 documentation, the :class:`_orm.Mapper` was
not accepting the :func:`_orm.mapped_column` construct in this context. Ths
feature was already working for the :paramref:`_orm.Mapper.version_id_col`
and :paramref:`_orm.Mapper.polymorphic_on` parameters.

As part of this change, the ``__mapper_args__`` attribute may be specified
without using :func:`_orm.declared_attr` on a non-mapped mixin class,
including a ``"primary_key"`` entry that refers to :class:`_schema.Column`
or :func:`_orm.mapped_column` objects locally present on the mixin;
Declarative will also translate these columns into the correct ones for a
particular mapped class. This again was working already for the
:paramref:`_orm.Mapper.version_id_col` and
:paramref:`_orm.Mapper.polymorphic_on` parameters.  Additionally,
elements within ``"primary_key"`` may be indicated as string names of
existing mapped properties.

Fixes: #9240
Change-Id: Ie2000273289fa23e0af21ef9c6feb3962a8b848c

2 years agoAdd 'or' comment between code blocks (#9236)
AM-ops [Sat, 4 Feb 2023 19:12:57 +0000 (21:12 +0200)] 
Add 'or' comment between code blocks (#9236)

2 years agouse tox extras
Mike Bayer [Fri, 3 Feb 2023 20:44:47 +0000 (15:44 -0500)] 
use tox extras

per tox devs [1] it's better we use "extras" explcitly
rather than putting our extras in deps

[1] https://github.com/tox-dev/tox/issues/2898#issuecomment-1407921041

Change-Id: Ib57bc1277a462b270e243b1bb4cdb55a80449256

2 years agoMerge "Fixed regression when using from_statement in orm context." into main
Federico Caselli [Fri, 3 Feb 2023 19:38:55 +0000 (19:38 +0000)] 
Merge "Fixed regression when using from_statement in orm context." into main

2 years agodisallow ORM instrumented attributes from reaching dataclasses
Mike Bayer [Fri, 3 Feb 2023 15:50:14 +0000 (10:50 -0500)] 
disallow ORM instrumented attributes from reaching dataclasses

More adjustments to ORM Declarative Dataclasses mappings, building on the
improved support for mixins with dataclasses added in 2.0.1 via
:ticket:`9179`, where a combination of using mixins plus ORM inheritance
would mis-classify fields in some cases leading to their dataclass
arguments such as ``init=False`` being lost.

Fixes: #9226
Change-Id: Ia36f413e23e91dfbdb900f5ff3f8cdd3d5847064

2 years agodont add non-server-side cols to returning for versioning
Mike Bayer [Thu, 2 Feb 2023 22:22:22 +0000 (17:22 -0500)] 
dont add non-server-side cols to returning for versioning

Fixed regression where using the :paramref:`_orm.Mapper.version_id_col`
feature with a regular Python-side incrementing column would fail to work
for SQLite and other databases that don't support "rowcount" with
"RETURNING", as "RETURNING" would be assumed for such columns even though
that's not what actually takes place.

Fixes: #9228
Change-Id: I6a1a7fa4d63e183fe4ef0fbfd3cb5cac03b26d78

2 years agoFixed regression when using from_statement in orm context.
Mike Bayer [Wed, 1 Feb 2023 23:16:39 +0000 (18:16 -0500)] 
Fixed regression when using from_statement in orm context.

Fixed regression when using :meth:`_sql.Select.from_statement` in an ORM
context, where matching of columns to SQL labels based on name alone was
disabled for ORM-statements that weren't fully textual. This would prevent
arbitrary SQL expressions with column-name labels from matching up to the
entity to be loaded, which previously would work within the 1.4
and previous series, so the previous behavior has been restored.

Fixes: #9217
Change-Id: I5f7ab9710a96a98241388883365e56d308b4daf2

2 years agoUse correct dialect annotation
Federico Caselli [Thu, 2 Feb 2023 19:19:26 +0000 (20:19 +0100)] 
Use correct dialect annotation

Fixes: #9222
Change-Id: Ife841a5cf5ec896405e84d8570ef63ce6176a5ec

2 years agoimprove typing issue template
Federico Caselli [Wed, 1 Feb 2023 20:42:03 +0000 (21:42 +0100)] 
improve typing issue template

Change-Id: Ifa68268ddeef0de20bfe95cb1991cc5de0250962

2 years agoFix minor documentation glitch, replace "row" with "column" (#9215)
Lele Gaifax [Wed, 1 Feb 2023 19:24:53 +0000 (20:24 +0100)] 
Fix minor documentation glitch, replace "row" with "column" (#9215)

2 years agoVersion 2.0.2 placeholder
Mike Bayer [Wed, 1 Feb 2023 17:28:23 +0000 (12:28 -0500)] 
Version 2.0.2 placeholder

2 years ago- 2.0.1 rel_2_0_1
Mike Bayer [Wed, 1 Feb 2023 17:11:59 +0000 (12:11 -0500)] 
- 2.0.1

2 years agochangelog tweaks
Mike Bayer [Wed, 1 Feb 2023 17:11:30 +0000 (12:11 -0500)] 
changelog tweaks

Change-Id: I479adc6f387a31dbaf232fa22374118c1ce94bea

2 years agofix late-eval example
Mike Bayer [Wed, 1 Feb 2023 16:18:55 +0000 (11:18 -0500)] 
fix late-eval example

Fixes: #9209
Change-Id: Ic5bc87b25281e3cecc967843c402e96c7c2a3dbb

2 years agoMerge "Add support for typing.Literal in Mapped" into main
mike bayer [Wed, 1 Feb 2023 15:55:16 +0000 (15:55 +0000)] 
Merge "Add support for typing.Literal in Mapped" into main

2 years agoAdd support for typing.Literal in Mapped
Frederik Aalund [Mon, 30 Jan 2023 16:50:40 +0000 (11:50 -0500)] 
Add support for typing.Literal in Mapped

Added support for :pep:`586` ``Literal`` to be used in the
:paramref:`_orm.registry.type_annotation_map` as well as within
:class:`.Mapped` constructs. To use custom types such as these, they must
appear explicitly within the :paramref:`_orm.registry.type_annotation_map`
to be mapped.  Pull request courtesy Frederik Aalund.

As part of this change, the support for :class:`.sqltypes.Enum` in the
:paramref:`_orm.registry.type_annotation_map` has been expanded to include
support for ``Literal[]`` types consisting of string values to be used,
in addition to ``enum.Enum`` datatypes.    If a ``Literal[]`` datatype
is used within ``Mapped[]`` that is not linked in
:paramref:`_orm.registry.type_annotation_map` to a specific datatype,
a :class:`.sqltypes.Enum` will be used by default.

Fixed issue involving the use of :class:`.sqltypes.Enum` within the
:paramref:`_orm.registry.type_annotation_map` where the
:paramref:`_sqltypes.Enum.native_enum` parameter would not be correctly
copied to the mapped column datatype, if it were overridden
as stated in the documentation to set this parameter to False.

Fixes: #9187
Fixes: #9200
Closes: #9191
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9191
Pull-request-sha: 7d13f705307bf62560fc831f6f049a425d411374

Change-Id: Ife3ba2655f4897f806d6a9cf0041c69fd4f39e9d

2 years agoMerge "Fixed typing of limit, offset and fetch to allow ``None``." into main
Federico Caselli [Tue, 31 Jan 2023 22:08:07 +0000 (22:08 +0000)] 
Merge "Fixed typing of limit, offset and fetch to allow ``None``." into main

2 years agoMerge "Unify doc typing" into main
Federico Caselli [Tue, 31 Jan 2023 22:01:34 +0000 (22:01 +0000)] 
Merge "Unify doc typing" into main

2 years agoFixed typing of limit, offset and fetch to allow ``None``.
Federico Caselli [Tue, 31 Jan 2023 20:20:26 +0000 (21:20 +0100)] 
Fixed typing of limit, offset and fetch to allow ``None``.

Fixes: #9183
Change-Id: I1ac3e3698034826122ea8a0cdc9f8f55a10ed6c1

2 years agoUnify doc typing
Harry Lees [Tue, 31 Jan 2023 13:38:34 +0000 (08:38 -0500)] 
Unify doc typing

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

Fixes #9168

This PR replaces common occurrences of [PEP 585](https://peps.python.org/pep-0585/) style type annotations with annotations compatible with older versions of Python.

I searched for instances of the following supported types from the PEP and replaced with their legacy typing couterparts.

* tuple # typing.Tuple
* list # typing.List
* dict # typing.Dict
* set # typing.Set
* frozenset # typing.FrozenSet
* type # typing.Type

```
grep -r "list\[.*\]" ./build --exclude-dir="./build/venv/*" --exclude-dir="./build/output/*" --exclude="changelog_[0-9]*\.rst"
```

I excluded changelog files from being altered, I think some of these could be changed if necessary but others are likely to require manual checking as the change may target the new typing style specifically.

For any examples that included imports, I tried to ensure that the correct typing imports were included and properly ordered.

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

Closes: #9198
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9198
Pull-request-sha: 05ad4651b57c6275b29433e5e76e166344ba6c4c

Change-Id: I41b93b3dee85f9fe00cfbb3d3eb011212795de29