]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/log
thirdparty/sqlalchemy/sqlalchemy.git
3 years agoadd contextual detail to cython change message
Mike Bayer [Tue, 14 Jun 2022 14:10:30 +0000 (10:10 -0400)] 
add contextual detail to cython change message

Change-Id: I57014a16f4718bdbe6eb91b8aeed7075cb4df5f1

3 years agoremove docs from path ignore in the tests
Federico Caselli [Mon, 13 Jun 2022 19:48:34 +0000 (21:48 +0200)] 
remove docs from path ignore in the tests

Change-Id: I1d399d9532bc63d00a730e3981aef79ad99a97bb

3 years agoneed to use List here since we test on 3.7 at the moment
Mike Bayer [Mon, 13 Jun 2022 16:41:44 +0000 (12:41 -0400)] 
need to use List here since we test on 3.7 at the moment

Change-Id: I8a92fb81a71ae3936f299e2794f1d710fea0a589

3 years agoedits
Mike Bayer [Mon, 13 Jun 2022 15:58:46 +0000 (11:58 -0400)] 
edits

i dont have a good way to preview this.  not sure how i should
be editing here.

Change-Id: I399a5b0fa3fd2a03bbdc66f3a1dcb21043f7214a

3 years agoedits
Mike Bayer [Mon, 13 Jun 2022 15:56:04 +0000 (11:56 -0400)] 
edits

Change-Id: Id0bf143e948255c473558c68b3471fbe62bd98f6

3 years agotry to encourage more discussions, less bugs
Mike Bayer [Mon, 13 Jun 2022 15:54:06 +0000 (11:54 -0400)] 
try to encourage more discussions, less bugs

Change-Id: If7e07fffeea6d32af4f2e819111315783e902b8e

3 years agoMerge "add auto_recurse option to selectinload, immediateload" into main
mike bayer [Sun, 12 Jun 2022 17:46:33 +0000 (17:46 +0000)] 
Merge "add auto_recurse option to selectinload, immediateload" into main

3 years agoupdate quickstart for 2.0
Mike Bayer [Sun, 12 Jun 2022 16:07:54 +0000 (12:07 -0400)] 
update quickstart for 2.0

this is just so we can point people to something
while I get around to doing the rest of the docs

Change-Id: Ie818024a80ad30b76d7f7d6dc179939c246084c6

3 years agoadd auto_recurse option to selectinload, immediateload
Mike Bayer [Sat, 11 Jun 2022 15:33:46 +0000 (11:33 -0400)] 
add auto_recurse option to selectinload, immediateload

Added very experimental feature to the :func:`_orm.selectinload` and
:func:`_orm.immediateload` loader options called
:paramref:`_orm.selectinload.auto_recurse` /
:paramref:`_orm.immediateload.auto_recurse` , which when set to True will
cause a self-referential relationship load to continue loading with
arbitrary depth until no further objects are found. This may be useful for
self-referential structures that must be loaded fully eagerly, such as when
using asyncio.

Fixes: #8126
Change-Id: I5bbd00bd0ca43f4649b44680fea1e84680f0a5db

3 years agoMerge "honor enum length in all cases" into main
mike bayer [Fri, 10 Jun 2022 18:19:06 +0000 (18:19 +0000)] 
Merge "honor enum length in all cases" into main

3 years agoMerge "resolve large ints to BigInteger" into main
mike bayer [Fri, 10 Jun 2022 18:18:35 +0000 (18:18 +0000)] 
Merge "resolve large ints to BigInteger" into main

3 years agoresolve large ints to BigInteger
Mike Bayer [Fri, 10 Jun 2022 16:57:53 +0000 (12:57 -0400)] 
resolve large ints to BigInteger

The in-place type detection for Python integers, as occurs with an
expression such as ``literal(25)``, will now apply value-based adaption as
well to accommodate Python large integers, where the datatype determined
will be :class:`.BigInteger` rather than :class:`.Integer`. This
accommodates for dialects such as that of asyncpg which both sends implicit
typing information to the driver as well as is sensitive to numeric scale.

Fixes: #7909
Change-Id: I1cd3ec2676c9bb03ffedb600695252bd0037ba02

3 years agohonor enum length in all cases
Mike Bayer [Fri, 10 Jun 2022 16:42:54 +0000 (12:42 -0400)] 
honor enum length in all cases

The :paramref:`.Enum.length` parameter, which sets the length of the
``VARCHAR`` column for non-native enumeration types, is now used
unconditionally when emitting DDL for the ``VARCHAR`` datatype, including
when the :paramref:`.Enum.native_enum` parameter is set to ``True`` for
target backends that continue to use ``VARCHAR``. Previously the parameter
would be erroneously ignored in this case. The warning previously emitted
for this case is now removed.

Fixes: #7791
Change-Id: I91764546b56e9416479949be8a118cdc91ac5ed9

3 years agoremove "undefer_pks" as a strategy option
Mike Bayer [Fri, 10 Jun 2022 15:44:45 +0000 (11:44 -0400)] 
remove "undefer_pks" as a strategy option

The behavior of :func:`_orm.defer` regarding primary key and "polymorphic
discriminator" columns is revised such that these columns are no longer
deferrable, either explicitly or when using a wildcard such as
``defer('*')``. Previously, a wildcard deferral would not load
PK/polymorphic columns which led to errors in all cases, as the ORM relies
upon these columns to produce object identities. The behavior of explicit
deferral of primary key columns is unchanged as these deferrals already
were implicitly ignored.

Fixes: #7495
Change-Id: I76d9252426e86619bc142667670a3df75b4f5f6a

3 years agoMerge "update cx_Oracle / oracledb LOB handling" into main
mike bayer [Fri, 10 Jun 2022 15:11:44 +0000 (15:11 +0000)] 
Merge "update cx_Oracle / oracledb LOB handling" into main

3 years agoupdate cx_Oracle / oracledb LOB handling
Mike Bayer [Tue, 7 Jun 2022 20:09:35 +0000 (16:09 -0400)] 
update cx_Oracle / oracledb LOB handling

Adjustments made to the BLOB / CLOB / NCLOB datatypes in the cx_Oracle and
oracledb dialects, to improve performance based on recommendations from
Oracle developers.

References: https://github.com/oracle/python-cx_Oracle/issues/596
Fixes: #7494
Change-Id: I0d8cc3579140aa65cacf5b7d3373f7e1929a8f85

3 years agoMerge "restore parameter escaping for public methods" into main
mike bayer [Thu, 9 Jun 2022 16:03:53 +0000 (16:03 +0000)] 
Merge "restore parameter escaping for public methods" into main

3 years agoMerge "handle non-mapped mixins for with_loader_criteria reduce" into main
mike bayer [Thu, 9 Jun 2022 16:02:21 +0000 (16:02 +0000)] 
Merge "handle non-mapped mixins for with_loader_criteria reduce" into main

3 years agoMerge "dont transfer __weakref__ to regenerated class" into main
mike bayer [Thu, 9 Jun 2022 16:01:26 +0000 (16:01 +0000)] 
Merge "dont transfer __weakref__ to regenerated class" into main

3 years agoRevert "document thread safety workaround for lambda statements"
Mike Bayer [Thu, 9 Jun 2022 14:56:59 +0000 (10:56 -0400)] 
Revert "document thread safety workaround for lambda statements"

This reverts commit bf40bade26e32fc3757bbd756f4c9ebdc5d72090.

3 years agorestore parameter escaping for public methods
Mike Bayer [Thu, 9 Jun 2022 01:35:02 +0000 (21:35 -0400)] 
restore parameter escaping for public methods

Adjusted the fix made for :ticket:`8056` which adjusted the escaping of
bound parameter names with special characters such that the escaped names
were translated after the SQL compilation step, which broke a published
recipe on the FAQ illustrating how to merge parameter names into the string
output of a compiled SQL string. The change restores the escaped names that
come from ``compiled.params`` and adds a conditional parameter to
:meth:`.SQLCompiler.construct_params` named ``escape_names`` that defaults
to ``True``, restoring the old behavior by default.

Fixes: #8113
Change-Id: I9cbedb1080bc06d51f287fd2cbf26aaab1c74653

3 years agodont transfer __weakref__ to regenerated class
Mike Bayer [Thu, 9 Jun 2022 13:53:43 +0000 (09:53 -0400)] 
dont transfer __weakref__ to regenerated class

Repaired a deprecation warning class decorator that was preventing key
objects such as :class:`_engine.Connection` from having a proper
``__weakref__`` attribute, causing operations like Python standard library
``inspect.getmembers()`` to fail.

Fixes: #8115
Change-Id: Ifd0bc2325fb9dc9e1431998c308b7fc081968373

3 years agohandle non-mapped mixins for with_loader_criteria reduce
Mike Bayer [Thu, 9 Jun 2022 12:55:14 +0000 (08:55 -0400)] 
handle non-mapped mixins for with_loader_criteria reduce

special handling is needed for a with_loader_criteria()
against a non-mapped mixin class.  added that to test
coverage

Fixes: #8109
Change-Id: Ia599361c8faab008e92095eb4607d02820f590d5

3 years agoMerge "fix race conditions in lambda statements" into main
mike bayer [Thu, 9 Jun 2022 12:37:17 +0000 (12:37 +0000)] 
Merge "fix race conditions in lambda statements" into main

3 years agoMerge "suppport with_loader_criteria pickling w/ fixed callable" into main
mike bayer [Thu, 9 Jun 2022 00:54:16 +0000 (00:54 +0000)] 
Merge "suppport with_loader_criteria pickling w/ fixed callable" into main

3 years agoadd tests to confirm no issue w/ pg json keys
Mike Bayer [Wed, 8 Jun 2022 23:04:23 +0000 (19:04 -0400)] 
add tests to confirm no issue w/ pg json keys

Change-Id: Ie91e5efb217c309bc40c3933f538bcf29c1fd87b
References: #8112

3 years agodocument thread safety workaround for lambda statements
Mike Bayer [Wed, 8 Jun 2022 20:03:26 +0000 (16:03 -0400)] 
document thread safety workaround for lambda statements

Change-Id: Idb7840ff64487ef985087a28bb6e96088e6a392e
References: #8098

3 years agoMerge "graceful degrade for FKs not reflectable" into main
mike bayer [Wed, 8 Jun 2022 17:13:28 +0000 (17:13 +0000)] 
Merge "graceful degrade for FKs not reflectable" into main

3 years agosuppport with_loader_criteria pickling w/ fixed callable
Mike Bayer [Wed, 8 Jun 2022 17:05:20 +0000 (13:05 -0400)] 
suppport with_loader_criteria pickling w/ fixed callable

Fixed issue where a :func:`_orm.with_loader_criteria` option could not be
pickled, as is necessary when it is carried along for propagation to lazy
loaders in conjunction with a caching scheme. Currently, the only form that
is supported as picklable is to pass the "where criteria" as a fixed
module-level callable function that produces a SQL expression. An ad-hoc
"lambda" can't be pickled, and a SQL expression object is usually not fully
picklable directly.

Fixes: #8109
Change-Id: I49fe69088b0c7e58a0f22c67d2ea4e33752a5a73

3 years agoadd note re: pickling for loader criteria
Mike Bayer [Wed, 8 Jun 2022 15:54:46 +0000 (11:54 -0400)] 
add note re: pickling for loader criteria

Change-Id: I75992af71ba08799a03995178a6e4612c9a7428a
References: #8108

3 years agofix race conditions in lambda statements
Mike Bayer [Tue, 7 Jun 2022 19:00:20 +0000 (15:00 -0400)] 
fix race conditions in lambda statements

Fixed multiple observed race conditions related to :func:`.lambda_stmt`,
including an initial "dogpile" issue when a new Python code object is
initially analyzed among multiple simultaneous threads which created both a
performance issue as well as some internal corruption of state.
Additionally repaired observed race condition which could occur when
"cloning" an expression construct that is also in the process of being
compiled or otherwise accessed in a different thread due to memoized
attributes altering the ``__dict__`` while iterated, for Python versions
prior to 3.10; in particular the lambda SQL construct is sensitive to this
as it holds onto a single statement object persistently. The iteration has
been refined to use ``dict.copy()`` with or without an additional iteration
instead.

Fixes: #8098
Change-Id: I4e0b627bfa187f1780dc68ec81b94db1c78f846a

3 years agoMerge "Add support for the new oracle driver ``oracledb``." into main
mike bayer [Tue, 7 Jun 2022 18:46:36 +0000 (18:46 +0000)] 
Merge "Add support for the new oracle driver ``oracledb``." into main

3 years agoMerge "migrate labels to new tutorial" into main
mike bayer [Tue, 7 Jun 2022 17:02:20 +0000 (17:02 +0000)] 
Merge "migrate labels to new tutorial" into main

3 years agoAdd support for the new oracle driver ``oracledb``.
Federico Caselli [Fri, 3 Jun 2022 12:51:04 +0000 (14:51 +0200)] 
Add support for the new oracle driver ``oracledb``.

Fixes: #8054
Change-Id: Idd7c1bbb7ca39499f53bdf59a63a6a9d65f144a5

3 years agograceful degrade for FKs not reflectable
Mike Bayer [Tue, 7 Jun 2022 13:40:26 +0000 (09:40 -0400)] 
graceful degrade for FKs not reflectable

Fixed bugs involving the :paramref:`.Table.include_columns` and the
:paramref:`.Table.resolve_fks` parameters on :class:`.Table`; these
little-used parameters were apparently not working for columns that refer
to foreign key constraints.

In the first case, not-included columns that refer to foreign keys would
still attempt to create a :class:`.ForeignKey` object, producing errors
when attempting to resolve the columns for the foreign key constraint
within reflection; foreign key constraints that refer to skipped columns
are now omitted from the table reflection process in the same way as
occurs for :class:`.Index` and :class:`.UniqueConstraint` objects with the
same conditions. No warning is produced however, as we likely want to
remove the include_columns warnings for all constraints in 2.0.

In the latter case, the production of table aliases or subqueries would
fail on an FK related table not found despite the presence of
``resolve_fks=False``; the logic has been repaired so that if a related
table is not found, the :class:`.ForeignKey` object is still proxied to the
aliased table or subquery (these :class:`.ForeignKey` objects are normally
used in the production of join conditions), but it is sent with a flag that
it's not resolvable. The aliased table / subquery will then work normally,
with the exception that it cannot be used to generate a join condition
automatically, as the foreign key information is missing. This was already
the behavior for such foreign key constraints produced using non-reflection
methods, such as joining :class:`.Table` objects from different
:class:`.MetaData` collections.

Fixes: #8100
Fixes: #8101
Change-Id: Ifa37a91bd1f1785fca85ef163eec031660d9ea4d

3 years agomigrate labels to new tutorial
Mike Bayer [Sat, 4 Jun 2022 19:53:34 +0000 (15:53 -0400)] 
migrate labels to new tutorial

other org changes and some sections from old tutorial
ported to new tutorial.

Change-Id: Ic0fba60ec82fff481890887beef9ed0fa271875a

3 years agorun test_update_rowcount_return_defaults only w/ returning
Mike Bayer [Mon, 6 Jun 2022 14:58:59 +0000 (10:58 -0400)] 
run test_update_rowcount_return_defaults only w/ returning

sane_rowcount_w_returning asserts failure, which will only
occur here if the DBAPI actually uses RETURNING.

as SQLite conditionally supports RETURNING which breaks
rowcount support only if present, limit this test to that
case.

Additionally, newer pysqlites will likely fix the issue so
we will probably want to put a sqlite3_version check as well
once that fix is released.

Change-Id: I065aa181eb48363c1024550ae3622486ae0b4a6e

3 years agoMerge "Generalize RETURNING and suppor for MariaDB / SQLite" into main
mike bayer [Sun, 5 Jun 2022 20:40:41 +0000 (20:40 +0000)] 
Merge "Generalize RETURNING and suppor for MariaDB / SQLite" into main

3 years agoDocs Update - Add **kwargs to CaseInsensitiveComparator docs (#8063)
Justin Crown [Sat, 4 Jun 2022 20:10:38 +0000 (16:10 -0400)] 
Docs Update - Add **kwargs to CaseInsensitiveComparator docs (#8063)

* Add **kwargs to CaseInsensitiveComparator docs

* add kwargs to other operate examples

Change-Id: I70a1e68bca27c2355ad3b7c5bbc538027f112bd9

* missed one entry

Change-Id: Ieb4a18ab6d96e588e9ec7672cfa65fe2fd8301e5

Co-authored-by: Federico Caselli <cfederico87@gmail.com>
3 years agoMerge "Fixed orm not applying fetch" into main
mike bayer [Sat, 4 Jun 2022 18:21:02 +0000 (18:21 +0000)] 
Merge "Fixed orm not applying fetch" into main

3 years agoFixed orm not applying fetch
Federico Caselli [Fri, 3 Jun 2022 10:13:10 +0000 (12:13 +0200)] 
Fixed orm not applying fetch

Fixed an issue where :meth:`_sql.GenerativeSelect.fetch` would be
ignored when executing a statement using the ORM.

Fixes: #8091
Change-Id: I6790c7272a71278e90de2529c8bc8ae89e54e288

3 years agofix some typos (#8093)
cui fliter [Sat, 4 Jun 2022 10:16:27 +0000 (18:16 +0800)] 
fix some typos (#8093)

Signed-off-by: cuishuang <imcusg@gmail.com>
3 years agoLink to dialect for Actian Avalanche, Vector, Actian X, and Ingres (#8039)
clach04 [Sat, 4 Jun 2022 10:15:17 +0000 (03:15 -0700)] 
Link to dialect for Actian Avalanche, Vector, Actian X, and Ingres (#8039)

3 years agodocs: spelling error (#8088)
Galen Rice [Sat, 4 Jun 2022 10:07:43 +0000 (06:07 -0400)] 
docs: spelling error (#8088)

Leave off the last S for savings!

3 years agosome typing fixes
Mike Bayer [Fri, 3 Jun 2022 14:34:19 +0000 (10:34 -0400)] 
some typing fixes

* ClassVar for decl fields, add __tablename__
* dataclasses require annotations for all fields.  For us,
  if no annotation, then skip that field as part of what is
  considered to be a "dataclass", as this matches the behavior
  of pyright right now.   We could alternatively raise on this
  use, which is what dataclasses does.   we should ask the pep
  people
* plain field that's just "str", "int", etc., with no value.
  Disallow it unless __allow_unmapped__ is set.   If field
  has dataclasses.field, Column, None, a value etc, it goes through,
  and when using dataclasses mixin all such fields are considered
  for the dataclass setup just like a dataclass.  Hopefully this
  does not have major backwards compat issues.  __allow_unmapped__
  can be set on the base class, mixins, etc., it's liberal for
  now in case people have this problem.
* accommodate for ClassVar, these are not considered at all for
  mapping.

Change-Id: Id743aa0456bade9a5d5832796caeecc3dc4accb7

3 years agoemphasize expire_on_commit in detached error docs
Mike Bayer [Thu, 2 Jun 2022 18:52:27 +0000 (14:52 -0400)] 
emphasize expire_on_commit in detached error docs

issues like #8082 suggest users are still not
fully aware of the need to set this parameter
when dealing with detached objects.

Change-Id: I6f389fdbe18b9c977bfb8188fc4732dbd56884d9

3 years agoGeneralize RETURNING and suppor for MariaDB / SQLite
Daniel Black [Tue, 28 Sep 2021 18:20:06 +0000 (14:20 -0400)] 
Generalize RETURNING and suppor for MariaDB / SQLite

As almost every dialect supports RETURNING now, RETURNING
is also made more of a default assumption.

* the default compiler generates a RETURNING clause now
  when specified; CompileError is no longer raised.
* The dialect-level implicit_returning parameter now has
  no effect.   It's not fully clear if there are real world
  cases relying on the dialect-level parameter, so we will see
  once 2.0 is released.   ORM-level RETURNING can be disabled
  at the table level, and perhaps "implicit returning" should
  become an ORM-level option at some point as that's where
  it applies.
* Altered ORM update() / delete() to respect table-level
  implicit returning for fetch.
* Since MariaDB doesnt support UPDATE returning, "full_returning"
  is now split into insert_returning, update_returning, delete_returning
* Crazy new thing.  Dialects that have *both* cursor.lastrowid
  *and* returning.   so now we can pick between them for SQLite
  and mariadb.  so, we are trying to keep it on .lastrowid for
  simple inserts with an autoincrement column, this helps with
  some edge case test scenarios and i bet .lastrowid is faster
  anyway.  any return_defaults() / multiparams etc then we
  use returning
* SQLite decided they dont want to return rows that match in
  ON CONFLICT.  this is flat out wrong, but for now we need to
  work with it.

Fixes: #6195
Fixes: #7011
Closes: #7047
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7047
Pull-request-sha: d25d5ea3abe094f282c53c7dd87f5f53a9e85248

Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I9908ce0ff7bdc50bd5b27722081767c31c19a950

3 years agoMerge "propagate proxy_key from WrapsColumnExpression" into main
mike bayer [Wed, 1 Jun 2022 17:27:13 +0000 (17:27 +0000)] 
Merge "propagate proxy_key from WrapsColumnExpression" into main

3 years agoMerge "add backend agnostic UUID datatype" into main
mike bayer [Wed, 1 Jun 2022 16:13:36 +0000 (16:13 +0000)] 
Merge "add backend agnostic UUID datatype" into main

3 years agopropagate proxy_key from WrapsColumnExpression
Mike Bayer [Wed, 1 Jun 2022 16:11:19 +0000 (12:11 -0400)] 
propagate proxy_key from WrapsColumnExpression

this allows cast() of a label() to propagate the
proxy key outwards in the same way that it apparently
works at the SQL level.

This is stuffing even more rules into naming so basically
seeing how far we can go without other cases starting
to fail.

Fixes: #8084
Change-Id: I20bd97dae798fee6492334c06934e807d0f269ef

3 years agoadd backend agnostic UUID datatype
Mike Bayer [Fri, 11 Feb 2022 09:54:45 +0000 (04:54 -0500)] 
add backend agnostic UUID datatype

Added new backend-agnostic :class:`_types.Uuid` datatype generalized from
the PostgreSQL dialects to now be a core type, as well as migrated
:class:`_types.UUID` from the PostgreSQL dialect. Thanks to Trevor Gross
for the help on this.

also includes:

* corrects some missing behaviors in the suite literal fixtures
  test where row round trips weren't being correctly asserted.
* fixes some of the ISO literal date rendering added in
  952383f9ee0 for #5052 to truncate datetime strings for date/time
  datatypes in the same way that drivers typically do for bound
  parameters; this was not working fully and wasn't caught by the
  broken test fixture

Fixes: #7212
Change-Id: I981ac6d34d278c18281c144430a528764c241b04

3 years agoMerge "Support handle_error for pre_ping" into main
mike bayer [Wed, 1 Jun 2022 13:58:17 +0000 (13:58 +0000)] 
Merge "Support handle_error for pre_ping" into main

3 years agocherry-pick changelog update for 1.4.38
Mike Bayer [Tue, 31 May 2022 21:28:09 +0000 (17:28 -0400)] 
cherry-pick changelog update for 1.4.38

3 years agocherry-pick changelog from 1.4.37
Mike Bayer [Tue, 31 May 2022 21:28:08 +0000 (17:28 -0400)] 
cherry-pick changelog from 1.4.37

3 years agochangelog fixes
Mike Bayer [Tue, 31 May 2022 21:21:39 +0000 (17:21 -0400)] 
changelog fixes

Change-Id: Id3fc3019f8eb799aa5adf6ca28e0aeedc0da31dd

3 years agoMerge "establish sessionmaker and async_sessionmaker as generic" into main
mike bayer [Tue, 31 May 2022 20:56:53 +0000 (20:56 +0000)] 
Merge "establish sessionmaker and async_sessionmaker as generic" into main

3 years agoMerge "Handle dead-connection errors for users of python-oracledb" into main
mike bayer [Tue, 31 May 2022 20:42:21 +0000 (20:42 +0000)] 
Merge "Handle dead-connection errors for users of python-oracledb" into main

3 years agoMerge "raise informative error when selectable can't be extended" into main
mike bayer [Tue, 31 May 2022 19:47:49 +0000 (19:47 +0000)] 
Merge "raise informative error when selectable can't be extended" into main

3 years agoUpdate declarative_styles.rst: Update code example to attrs TNG usage. (#8072)
Patrick Gerken [Tue, 31 May 2022 19:42:35 +0000 (21:42 +0200)] 
Update declarative_styles.rst: Update code example to attrs TNG usage. (#8072)

* Update declarative_styles.rst

Update docs to new style usage of attrs.
This is the default since December 2021.
While the old style still works, the newer one looks much nicer and is likely to be dominant pretty quickly. Imho.

* Update declarative_styles.rst

* Update declarative_styles.rst

3 years agoestablish sessionmaker and async_sessionmaker as generic
Mike Bayer [Thu, 26 May 2022 18:35:03 +0000 (14:35 -0400)] 
establish sessionmaker and async_sessionmaker as generic

This is so that custom Session and AsyncSession classes
can be typed for these factories.  Added appropriate
typevars to  `__call__()`, `__enter__()` and other methods
so that a custom Session or AsyncSession subclass is carried
through.

Fixes: #7656
Change-Id: Ia2b8c1f22b4410db26005c3285f6ba3d13d7f0e0

3 years agoSupport handle_error for pre_ping
Mike Bayer [Mon, 30 May 2022 16:29:58 +0000 (12:29 -0400)] 
Support handle_error for pre_ping

The :meth:`.DialectEvents.handle_error` event is now moved to the
:class:`.DialectEvents` suite from the :class:`.EngineEvents` suite, and
now participates in the connection pool "pre ping" event for those dialects
that make use of disconnect codes in order to detect if the database is
live. This allows end-user code to alter the state of "pre ping". Note that
this does not include dialects which contain a native "ping" method such as
that of psycopg2 or most MySQL dialects.

Fixes: #5648
Change-Id: I353d84a4f66f309d2467b7e67621db6b8c70411e

3 years agoraise informative error when selectable can't be extended
Mike Bayer [Tue, 31 May 2022 14:48:16 +0000 (10:48 -0400)] 
raise informative error when selectable can't be extended

An informative error is raised for the use case where
:meth:`.Insert.from_select` is being passed a "compound select" object such
as a UNION, yet the INSERT statement needs to append additional columns to
support Python-side or explicit SQL defaults from the table metadata. In
this case a subquery of the compound object should be passed.

Fixes: #8073
Change-Id: Ic4a5dbf84ec49d2451901be05cb9cf6ae93f02b7

3 years agoHandle dead-connection errors for users of python-oracledb
Christopher Jones [Tue, 31 May 2022 12:27:18 +0000 (08:27 -0400)] 
Handle dead-connection errors for users of python-oracledb

Added two new error codes for Oracle disconnect handling to support early
testing of the new "python-oracledb" driver released by Oracle.

Fixes: #8066
Closes: #8065
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8065
Pull-request-sha: d630b8457a1d29b7a1354ccc6d5e2956eea865f6

Change-Id: Ib14dbb888597b1087b1bb7c505ccad59df226177
(cherry picked from commit 2bf00472bfafd8fd0cca5b4fe55ff4faf1a1279e)
(cherry picked from commit 8564e2abf97795819f655a70b19b3bc820729c79)

3 years agorepair incorrect "cursor" var name in connection faq
Josep Pascual Badia [Mon, 30 May 2022 14:41:55 +0000 (10:41 -0400)] 
repair incorrect "cursor" var name in connection faq

Closes: #8075
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8075
Pull-request-sha: 34e5eaf3870f89c9c38ffe81121fa1b42e363752

Change-Id: Iab8cdc9f8da68ac955eea75efeba263d0a9dcb7b

3 years agoMerge "remove "deannotate" from column_property expression" into main
mike bayer [Sun, 29 May 2022 21:36:40 +0000 (21:36 +0000)] 
Merge "remove "deannotate" from column_property expression" into main

3 years agoMerge "move bindparam quote application from compiler to default" into main
mike bayer [Sun, 29 May 2022 21:34:37 +0000 (21:34 +0000)] 
Merge "move bindparam quote application from compiler to default" into main

3 years agoremove "deannotate" from column_property expression
Mike Bayer [Fri, 27 May 2022 20:07:01 +0000 (16:07 -0400)] 
remove "deannotate" from column_property expression

Fixed issue where using a :func:`_orm.column_property` construct containing
a subquery against an already-mapped column attribute would not correctly
apply ORM-compilation behaviors to the subquery, including that the "IN"
expression added for a single-table inherits expression would fail to be
included.

This fix involves a few tweaks in the ORM adaptation logic,
including a missing "parententity" adaptation on the mapper
side.  The specific mechanics here have a lot of moving parts
so we will continue to add tests to assert these cases.  In
particular a more complete test for issue #2316 is added
that was relying upon the deannotate happening here.

Fixes: #8064
Change-Id: Ia85dd12dcf6e7c002b30de4a27d7aa66cb3cd20e

3 years agomove bindparam quote application from compiler to default
Mike Bayer [Sun, 29 May 2022 16:07:46 +0000 (12:07 -0400)] 
move bindparam quote application from compiler to default

in 296c84313ab29bf9599634f3 for #5653 we generalized Oracle's
parameter escaping feature into the compiler, so that it could also
work for PostgreSQL.  The compiler used quoted names within parameter
dictionaries, which then led to the complexity that all functions
which interpreted keys from the compiled_params dict had to
also quote the param names to use the dictionary.  This
extra complexity was not added to the ORM peristence.py however,
which led to the versioning id feature being broken as well as
other areas where persistence.py relies on naming schemes present
in context.compiled_params.  It also was not added to the
"processors" lookup which led to #8053, that added this escaping
to that part of the compiler.

To both solve the whole problem as well as simplify the compiler
quite a bit, move the actual application of the escaped names
to be as late as possible, when default.py builds the final list
of parameters.  This is more similar to how it worked previously
where OracleExecutionContext would be late-applying these
escaped names.   This re-establishes context.compiled_params as
deterministically named regardless of dialect in use and moves
out the complexity of the quoted param names to be only at the
cursor.execute stage.

Fixed bug, likely a regression from 1.3, where usage of column names that
require bound parameter escaping, more concretely when using Oracle with
column names that require quoting such as those that start with an
underscore, or in less common cases with some PostgreSQL drivers when using
column names that contain percent signs, would cause the ORM versioning
feature to not work correctly if the versioning column itself had such a
name, as the ORM assumes certain bound parameter naming conventions that
were being interfered with via the quotes. This issue is related to
:ticket:`8053` and essentially revises the approach towards fixing this,
revising the original issue :ticket:`5653` that created the initial
implementation for generalized bound-parameter name quoting.

Fixes: #8056
Change-Id: I57b064e8f0d070e328b65789c30076f6a0ca0fef

3 years agomssql login failure if password starts with "{"
Gord Thompson [Sun, 29 May 2022 13:07:45 +0000 (07:07 -0600)] 
mssql login failure if password starts with "{"

Fix issue where a password with a leading "{" would
result in login failure.

Fixes: #8062
Change-Id: If91c2c211937b5eac89b8d525c22a19b0a94c5c4

3 years agoadd typing for PG UUID, other types
Mike Bayer [Fri, 27 May 2022 13:56:01 +0000 (09:56 -0400)] 
add typing for PG UUID, other types

note that UUID will be generalized into core with #7212.

Fixes: #6402
Change-Id: I90f0052ca74367c2c2f1ce2f8a90e81d173d1430

3 years agoQueryableAttribute can be used as DDL column
Mike Bayer [Thu, 26 May 2022 20:12:10 +0000 (16:12 -0400)] 
QueryableAttribute can be used as DDL column

We have a lot of mappings with like ForeignKey(A.id)
so this needs to be included.

Change-Id: I8ac4211fb09720f093fe7f6353f365ee1d7faaae

3 years agoMerge "bump bundle count" into main
mike bayer [Wed, 25 May 2022 17:09:53 +0000 (17:09 +0000)] 
Merge "bump bundle count" into main

3 years agoMerge "apply bindparam escape name to processors dictionary" into main
mike bayer [Wed, 25 May 2022 16:44:50 +0000 (16:44 +0000)] 
Merge "apply bindparam escape name to processors dictionary" into main

3 years agobump bundle count
Mike Bayer [Wed, 25 May 2022 16:40:02 +0000 (12:40 -0400)] 
bump bundle count

this count seems to have grown a bit.  can look into
the cause, but at the moment we need CI to pass.

Change-Id: Iea1e4900d5c5d3f80e7ce400a2b9cc1f313cef4c

3 years agoMerge "enable pg8000 for 1.29.1 and above" into main
mike bayer [Wed, 25 May 2022 14:12:41 +0000 (14:12 +0000)] 
Merge "enable pg8000 for 1.29.1 and above" into main

3 years agoapply bindparam escape name to processors dictionary
Mike Bayer [Wed, 25 May 2022 12:47:29 +0000 (08:47 -0400)] 
apply bindparam escape name to processors dictionary

Fixed SQL compiler issue where the "bind processing" function for a bound
parameter would not be correctly applied to a bound value if the bound
parameter's name were "escaped". Concretely, this applies, among other
cases, to Oracle when a :class:`.Column` has a name that itself requires
quoting, such that the quoting-required name is then used for the bound
parameters generated within DML statements, and the datatype in use
requires bind processing, such as the :class:`.Enum` datatype.

Fixes: #8053
Change-Id: I39d060a87e240b4ebcfccaa9c535e971b7255d99

3 years agouse random table name
Mike Bayer [Tue, 24 May 2022 16:27:59 +0000 (12:27 -0400)] 
use random table name

this test is failing on CI with "##foo does not exist",
so hypothesize there's some kind of race condition with
global temp table names.

Change-Id: I8c6c26a7fda70f67735ce20af67373c311e48731

3 years agoenable pg8000 for 1.29.1 and above
Mike Bayer [Mon, 23 May 2022 14:34:32 +0000 (10:34 -0400)] 
enable pg8000 for 1.29.1 and above

ROLLBACK TO SAVEPOINT is re-enabled
in https://github.com/tlocke/pg8000/issues/111.

we still have to add savepoint support to our fixture that
deletes from tables without checking for them.
this is inconvenient but not incorrect.

Change-Id: I2f4a0a3e18db93c3e6794ade9b0fee33d2e4b7dc

3 years agoMerge "render select froms first" into main
mike bayer [Mon, 23 May 2022 14:58:55 +0000 (14:58 +0000)] 
Merge "render select froms first" into main

3 years agoMerge "deprecate .connection on _ConnectionFairy, _ConnectionRecord" into main
mike bayer [Mon, 23 May 2022 14:58:03 +0000 (14:58 +0000)] 
Merge "deprecate .connection on _ConnectionFairy, _ConnectionRecord" into main

3 years agoMerge "Improvements on dataclass_transform feature" into main
mike bayer [Mon, 23 May 2022 14:57:24 +0000 (14:57 +0000)] 
Merge "Improvements on dataclass_transform feature" into main

3 years agoMerge "Add a note on using server_onupdate=FetchedValue()" into main
mike bayer [Mon, 23 May 2022 13:50:27 +0000 (13:50 +0000)] 
Merge "Add a note on using server_onupdate=FetchedValue()" into main

3 years agoremove insanely old note from 12 years ago
Mike Bayer [Mon, 23 May 2022 13:48:05 +0000 (09:48 -0400)] 
remove insanely old note from 12 years ago

Change-Id: Id0929b6bc062fc4766c9c69427524e3cd2da1030

3 years agoMerge "Format code in documentation" into main
mike bayer [Mon, 23 May 2022 13:37:30 +0000 (13:37 +0000)] 
Merge "Format code in documentation" into main

3 years agoAdd a note on using server_onupdate=FetchedValue()
Andrew Brookins [Sun, 22 May 2022 20:24:15 +0000 (16:24 -0400)] 
Add a note on using server_onupdate=FetchedValue()

Add a note on using `server_onupdate=FetchedValue()` when using SQL expressions with `onupdate`.

My team encountered an issue with using a SQL expression with `onupdate`.
Despite the dialect (PG) supporting `RETURNING`, we needed to mark the column with
`server_onupdate=FetchedValue()` in order to get the column used with `onupdate`
to appear in the `RETURNING` clause of `UPDATE` statements.

This was not clear from the documentation, so I want to make it crystal clear for other
folks defining similar columns.

Closes: #7437
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7437
Pull-request-sha: 4845fb09a90ab58f0ae882e0d335ddba09b32ca0

Change-Id: I272278830c8f3f42d057ff77c3209e87df7adf02

3 years agoFormat code in documentation
Doctor [Sun, 22 May 2022 20:05:25 +0000 (16:05 -0400)] 
Format code in documentation

Closes: #7959
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7959
Pull-request-sha: fd8f60fcfe9cda0c2ba6dc9ddd171bf85a180295

Change-Id: I9a96c6e3e56cfd550672db4c1da4d68a961f970a

3 years agouse plainto_tsquery for PG match
Mike Bayer [Wed, 18 May 2022 20:06:29 +0000 (16:06 -0400)] 
use plainto_tsquery for PG match

The :meth:`.Operators.match` operator now uses ``plainto_tsquery()`` for
PostgreSQL full text search, rather than ``to_tsquery()``. The rationale
for this change is to provide better cross-compatibility with match on
other database backends.    Full support for all PostgreSQL full text
functions remains available through the use of :data:`.func` in
conjunction with :meth:`.Operators.bool_op` (an improved version of
:meth:`.Operators.op` for boolean operators).

Additional doc updates here apply to 1.4 so will backport these
out to a separate commit.

Fixes: #7086
Change-Id: I1946075daf5d9c558e85f73f1bf852604b3b1b8c

3 years agorender select froms first
Mike Bayer [Fri, 20 May 2022 19:56:54 +0000 (15:56 -0400)] 
render select froms first

The FROM clauses that are established on a :func:`_sql.select` construct
when using the :meth:`_sql.Select.select_from` method will now render first
in the FROM clause of the rendered SELECT, which serves to maintain the
ordering of clauses as was passed to the :meth:`_sql.Select.select_from`
method itself without being affected by the presence of those clauses also
being mentioned in other parts of the query. If other elements of the
:class:`_sql.Select` also generate FROM clauses, such as the columns clause
or WHERE clause, these will render after the clauses delivered by
:meth:`_sql.Select.select_from` assuming they were not explictly passed to
:meth:`_sql.Select.select_from` also. This improvement is useful in those
cases where a particular database generates a desirable query plan based on
a particular ordering of FROM clauses and allows full control over the
ordering of FROM clauses.

Fixes: #7888
Change-Id: I740f262a3841f829239011120a59b5e58452db5b

3 years agodeprecate .connection on _ConnectionFairy, _ConnectionRecord
Mike Bayer [Sun, 22 May 2022 18:28:14 +0000 (14:28 -0400)] 
deprecate .connection on _ConnectionFairy, _ConnectionRecord

These are replaced by the read-only ManagesConnection.dbapi_connection
attribute.

For some reason both of these objects had "setter" for .connection
as well; there's no use case for that at all so just remove
setter logic entirely.

Fixes: #6981
Change-Id: I6425de4a017f6370e1a7476cd491cabc55e55e67

3 years agoImprovements on dataclass_transform feature
Federico Caselli [Sat, 21 May 2022 09:32:37 +0000 (11:32 +0200)] 
Improvements on dataclass_transform feature

Change-Id: Iaf80526b70368cd4ed4147fdce9f6525b113474a

3 years agoMerge "block pg8000 >=1.29" into main
mike bayer [Sun, 22 May 2022 15:13:45 +0000 (15:13 +0000)] 
Merge "block pg8000 >=1.29" into main

3 years agodisable psycopg-c from dbapimain builds
Mike Bayer [Sun, 22 May 2022 14:32:02 +0000 (10:32 -0400)] 
disable psycopg-c from dbapimain builds

I don't know what this means.

ERROR:

Command errored out with exit status 1:
   command: /home/classic/tmp/foo/.venv/bin/python /home/classic/tmp/foo/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmp1x3hi09h
       cwd: /tmp/pip-install-yo6y28dm/psycopg-c_18eb2a0429dc438493454ed1051296ad
  Complete output (14 lines):
  error: Multiple top-level packages discovered in a flat-layout: ['psycopg', 'psycopg_c', 'psycopg_pool'].

  To avoid accidental inclusion of unwanted files or directories,
  setuptools will not proceed with this build.

  If you are trying to create a single distribution with multiple packages
  on purpose, you should not rely on automatic discovery.
  Instead, consider the following options:

  1. set up custom discovery (`find` directive with `include` or `exclude`)
  2. use a `src-layout`
  3. explicitly set `py_modules` or `packages` with a list of names

  To find more information, look for "package discovery" on setuptools docs.

Change-Id: I703ccd0a776fb7d0877acbbf919583102aa76fad

3 years agoblock pg8000 >=1.29
Mike Bayer [Sun, 22 May 2022 14:19:18 +0000 (10:19 -0400)] 
block pg8000 >=1.29

Issue at https://github.com/tlocke/pg8000/issues/111
prevents savepoints from being usable.

Change-Id: Ic689cf065c47aea5a146d30c47eb9bbfe8375692

3 years agoMerge "Use collation in reflection in MSSQL" into main
mike bayer [Sat, 21 May 2022 14:03:59 +0000 (14:03 +0000)] 
Merge "Use collation in reflection in MSSQL" into main

3 years agoUse collation in reflection in MSSQL
Federico Caselli [Wed, 18 May 2022 20:20:01 +0000 (22:20 +0200)] 
Use collation in reflection in MSSQL

Explicitly specify the collation when reflecting table columns using
MSSQL to prevent "collation conflict" errors.

Fixes: #8035
Change-Id: I4239a5ca8b041f56d7b3bba67b3357c176db31ee

3 years agoMerge "implement dataclass_transforms" into main
mike bayer [Fri, 20 May 2022 19:22:03 +0000 (19:22 +0000)] 
Merge "implement dataclass_transforms" into main

3 years agoimplement dataclass_transforms
Mike Bayer [Fri, 18 Feb 2022 15:05:12 +0000 (10:05 -0500)] 
implement dataclass_transforms

Implement a new means of creating a mapped dataclass where
instead of applying the `@dataclass` decorator distinctly,
the declarative process itself can create the dataclass.

MapperProperty and MappedColumn objects themselves take
the place of the dataclasses.Field object when constructing
the class.

The overall approach is made possible at the typing level
using pep-681 dataclass transforms [1].

This new approach should be able to completely supersede the
previous "dataclasses" approach of embedding metadata into
Field() objects, which remains a mutually exclusive declarative
setup style (mixing them introduces new issues that are not worth
solving).

[1] https://peps.python.org/pep-0681/#transform-descriptor-types-example

Fixes: #7642
Change-Id: I6ba88a87c5df38270317b4faf085904d91c8a63c

3 years agoMerge "Include new MySQL error code 4031 for MySQL disconnect check" into main
mike bayer [Thu, 19 May 2022 14:55:51 +0000 (14:55 +0000)] 
Merge "Include new MySQL error code 4031 for MySQL disconnect check" into main

3 years agoInclude new MySQL error code 4031 for MySQL disconnect check
valievkarim [Wed, 18 May 2022 20:24:41 +0000 (16:24 -0400)] 
Include new MySQL error code 4031 for MySQL disconnect check

Added disconnect code for MySQL error 4031, introduced in MySQL >= 8.0.24,
indicating connection idle timeout exceeded. In particular this repairs an
issue where pre-ping could not reconnect on a timed-out connection. Pull
request courtesy valievkarim.

Fixes: #8036
Closes: #8037
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8037
Pull-request-sha: 7ab605c2d25c3cd83af41e3250c97c623220cc7a

Change-Id: I21249c9d8acb305ac43ce61b90b41daf7fabdfe8

3 years agoMerge "Fix warnings raised by the testing module" into main
mike bayer [Thu, 19 May 2022 12:43:59 +0000 (12:43 +0000)] 
Merge "Fix warnings raised by the testing module" into main