]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/log
thirdparty/sqlalchemy/sqlalchemy.git
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 "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 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

3 years agoFix warnings raised by the testing module
Federico Caselli [Tue, 17 May 2022 20:26:20 +0000 (22:26 +0200)] 
Fix warnings raised by the testing module

Adjust the automatic stacklevel counter to ignore sqlalchemy.testing
Properly apply warning filters

Change-Id: Ib3d2eb6269af5fc72881df4d39194b3b0cbb1353

3 years agobool_op() wasn't added in 2.0
Mike Bayer [Wed, 18 May 2022 21:18:43 +0000 (17:18 -0400)] 
bool_op() wasn't added in 2.0

this method is in 1.4 as well, just doesn't do pep-484 yet.

Change-Id: I5a0aee8ad212864fc79e152ec9ea3bb3d12b6b04

3 years agoMerge "favor bool_op over op in comparison" into main
mike bayer [Wed, 18 May 2022 21:11:04 +0000 (21:11 +0000)] 
Merge "favor bool_op over op in comparison" into main

3 years agoUpdate dbapi_transactions.rst (#8032)
Robert Kulagowski [Wed, 18 May 2022 20:25:18 +0000 (15:25 -0500)] 
Update dbapi_transactions.rst (#8032)

If you're defining 'y=row.y' then you might as well use 'y' in the print statement.

3 years agofavor bool_op over op in comparison
Mike Bayer [Wed, 18 May 2022 20:21:49 +0000 (16:21 -0400)] 
favor bool_op over op in comparison

there's no need to use the is_comparison parameter
anymore as bool_op() works better and in 2.0 also does
typing correctly.

Change-Id: I9e92b665b112d40d90e539003b0efe00ed7b075f

3 years agoremove unused "descriptor" param from ColumnProperty
Mike Bayer [Tue, 17 May 2022 18:33:05 +0000 (14:33 -0400)] 
remove unused "descriptor" param from ColumnProperty

this appears to be unused and wasn't documented,
even though in the method sig for column_property().
just whack it

also repairs a typing issue in decl_base that seemed
to somehow not fail previously.

Change-Id: Id5c8e716b7e53715778921ab03707642cadbfdee

3 years agofix most sphinx warnings (1.4)
Mike Bayer [Mon, 16 May 2022 14:57:51 +0000 (10:57 -0400)] 
fix most sphinx warnings (1.4)

still can't figure out the warnings with some of the older
changelog files.

this cherry-picks the sphinx fixes from 1.4 and additionally
fixes a small number of new issues in the 2.0 docs. However,
2.0 has many more errors to fix, primarily from the removal
of the legacy tutorials left behind a lot of labels that need
to be re-linked to the new tutorial.

Fixes: #7946
Change-Id: Id657ab23008eed0b133fed65b2f9ea75a626215c
(cherry picked from commit 9b55a423459236ca8a2ced713c9e93999dd18922)

3 years agoMerge "ensure MappedColumn col is mapped under alternate key" into main
mike bayer [Mon, 16 May 2022 03:00:10 +0000 (03:00 +0000)] 
Merge "ensure MappedColumn col is mapped under alternate key" into main

3 years agoMerge "revenge of pep 484" into main
mike bayer [Mon, 16 May 2022 02:32:44 +0000 (02:32 +0000)] 
Merge "revenge of pep 484" into main

3 years agoensure MappedColumn col is mapped under alternate key
Mike Bayer [Mon, 16 May 2022 02:24:40 +0000 (22:24 -0400)] 
ensure MappedColumn col is mapped under alternate key

Fixes: #8025
Change-Id: I83ba54f05bd2e5fc87d80f42fbeb6d4d2f2ac5fa

3 years agorevenge of pep 484
Mike Bayer [Fri, 6 May 2022 20:09:52 +0000 (16:09 -0400)] 
revenge of pep 484

trying to get remaining must-haves for ORM

Change-Id: I66a3ecbbb8e5ba37c818c8a92737b576ecf012f7

3 years agoMerge "render col name in on conflict set clause, not given key" into main
mike bayer [Sun, 15 May 2022 23:27:50 +0000 (23:27 +0000)] 
Merge "render col name in on conflict set clause, not given key" into main

3 years agorender col name in on conflict set clause, not given key
Mike Bayer [Fri, 13 May 2022 20:08:34 +0000 (16:08 -0400)] 
render col name in on conflict set clause, not given key

Fixed bug where the PostgreSQL :meth:`_postgresql.Insert.on_conflict`
method and the SQLite :meth:`_sqlite.Insert.on_conflict` method would both
fail to correctly accommodate a column with a separate ".key" when
specifying the column using its key name in the dictionary passed to
``set_``, as well as if the :attr:`_sqlite.Insert.excluded` or
:attr:`_postgresql.Insert.excluded` collection were used as the dictionary
directly.

Fixes: #8014
Change-Id: I67226aeedcb2c683e22405af64720cc1f990f274

3 years agoraise for same param name in expanding + non expanding
Mike Bayer [Fri, 13 May 2022 19:43:53 +0000 (15:43 -0400)] 
raise for same param name in expanding + non expanding

An informative error is raised if two individual :class:`.BindParameter`
objects share the same name, yet one is used within an "expanding" context
(typically an IN expression) and the other is not; mixing the same name in
these two different styles of usage is not supported and typically the
``expanding=True`` parameter should be set on the parameters that are to
receive list values outside of IN expressions (where ``expanding`` is set
by default).

Fixes: #8018
Change-Id: Ie707f29680eea16b9e421af93560ac1958e11a54

3 years agoadjust log stacklevel for py3.11.0b1; enable greenlet
Mike Bayer [Sat, 14 May 2022 14:25:53 +0000 (10:25 -0400)] 
adjust log stacklevel for py3.11.0b1; enable greenlet

Fixed issue where support for logging "stacklevel" implemented in
:ticket:`7612` required adjustment to work with recently released Python
3.11.0b1, also repairs the unit tests which tested this feature.

Install greenlet from a py311 compat patch.

re: the stacklevel thing, this is going to be very inconvenient
if we have to keep hardcoding numbers everywhere for every
new python version

Change-Id: I0c8f7293e98c0ca5cc544538284bfd1d3020cb1f
References: https://github.com/python-greenlet/greenlet/issues/288
Fixes: #8019
3 years agoupdate for flake8-future-imports 0.0.5
Mike Bayer [Sat, 14 May 2022 15:13:50 +0000 (11:13 -0400)] 
update for flake8-future-imports 0.0.5

a whole bunch of errors were apparently blocked by 0.0.4
being installed.

Fixes: #8020
Change-Id: I22a0faeaabe03de501897893391946d677c2df7e

3 years agomore expire_on_commit reminders
Mike Bayer [Fri, 13 May 2022 14:25:37 +0000 (10:25 -0400)] 
more expire_on_commit reminders

the session commit/close docs still feel awkward in how
one learns about this operation.   hopefully another pass
over 2.0 can make things more linear.

removed a 1.4 note about autobegin that was completely inaccurate;
commit() does autobegin so it has an effect, just not usually
on the database.

Change-Id: Iaa4b96bd3df6cf82e851b2943322ddad7abbbac0

3 years agobump zimports to 0.6.0
Mike Bayer [Tue, 10 May 2022 14:32:18 +0000 (10:32 -0400)] 
bump zimports to 0.6.0

new multiprocessing support

Change-Id: I165a419a67c4e4a5e49d15cf2ac5c8aa46d16cbc

3 years agoMerge "dont use the label convention for memoized entities" into main
mike bayer [Mon, 9 May 2022 15:12:50 +0000 (15:12 +0000)] 
Merge "dont use the label convention for memoized entities" into main

3 years agodont use the label convention for memoized entities
Mike Bayer [Mon, 9 May 2022 14:27:51 +0000 (10:27 -0400)] 
dont use the label convention for memoized entities

Fixed issue where ORM results would apply incorrect key names to the
returned :class:`.Row` objects in the case where the set of columns to be
selected were changed, such as when using
:meth:`.Select.with_only_columns`.

Fixes: #8001
Change-Id: If3a2a5d00d15ebc2e9d41494845cfb3b06f80dcc

3 years agoexplicitly fetch inserted pk for values(pkcol=None)
Mike Bayer [Mon, 9 May 2022 02:49:33 +0000 (22:49 -0400)] 
explicitly fetch inserted pk for values(pkcol=None)

Altered the compilation mechanics of the :class:`.Insert` construct such
that the "autoincrement primary key" column value will be fetched via
``cursor.lastrowid`` or RETURNING even if present in the parameter set or
within the :meth:`.Insert.values` method as a plain bound value, for
single-row INSERT statements on specific backends that are known to
generate autoincrementing values even when explicit NULL is passed. This
restores a behavior that was in the 1.3 series for both the use case of
separate parameter set as well as :meth:`.Insert.values`. In 1.4, the
parameter set behavior unintentionally changed to no longer do this, but
the :meth:`.Insert.values` method would still fetch autoincrement values up
until 1.4.21 where :ticket:`6770` changed the behavior yet again again
unintentionally as this use case was never covered.

The behavior is now defined as "working" to suit the case where databases
such as SQLite, MySQL and MariaDB will ignore an explicit NULL primary key
value and nonetheless invoke an autoincrement generator.

Fixes: #7998
Change-Id: I5d4105a14217945f87fbe9a6f2a3c87f6ef20529

3 years agorun zimports to match pref changes
Mike Bayer [Fri, 6 May 2022 20:25:19 +0000 (16:25 -0400)] 
run zimports to match pref changes

I've turned "remove unused imports" back on so this
affects some not-used imports in TYPE_CHECKING blocks

Change-Id: I8b64ff4ec63f4cee01c2bf41399b691e1c3fb04a

3 years agoMerge "accept for literal coercions" into main
mike bayer [Fri, 6 May 2022 19:36:45 +0000 (19:36 +0000)] 
Merge "accept for literal coercions" into main

3 years agoaccept for literal coercions
Mike Bayer [Fri, 6 May 2022 14:13:03 +0000 (10:13 -0400)] 
accept for literal coercions

this may be needed in many more places but cast()
is a prominent one.

Change-Id: I5331edd2d34c54910e4ca16b0553f64fc9167af7

3 years agoMerge "pep484: attributes and related" into main
mike bayer [Tue, 3 May 2022 20:24:20 +0000 (20:24 +0000)] 
Merge "pep484: attributes and related" into main

3 years agoUse tuple instead of raw url in string formatting (#7987)
dzcode [Tue, 3 May 2022 20:18:43 +0000 (14:18 -0600)] 
Use tuple instead of raw url in string formatting (#7987)

* Fixes: #7902 - Use tuple instead of raw url in string formatting

* Fix lint error

3 years agodocs(types) Fix missing import from sqlalchemy (#7978)
khashashin [Tue, 3 May 2022 20:00:59 +0000 (22:00 +0200)] 
docs(types) Fix missing import from sqlalchemy (#7978)

* docs(types) Fix missing import from sqlalchemy

The sample code is missing the import of Enum from sqlalchemy, which might confuse the reader, since we are using another enum type from Python itself here. So it makes sense to clarify that here.

* fix whitespaces

Change-Id: I019bbed8a7278f60e7239160ea4c99ecd2519d3b

Co-authored-by: Federico Caselli <cfederico87@gmail.com>
3 years agopep484: attributes and related
Mike Bayer [Thu, 28 Apr 2022 20:19:43 +0000 (16:19 -0400)] 
pep484: attributes and related

also implements __slots__ for QueryableAttribute,
InstrumentedAttribute, Relationship.Comparator.

Change-Id: I47e823160706fc35a616f1179a06c7864089e5b5

3 years agobypass pyodbc default server version / set charset
Mike Bayer [Tue, 3 May 2022 12:58:27 +0000 (08:58 -0400)] 
bypass pyodbc default server version / set charset

Further adjustments to the MySQL PyODBC dialect to allow for complete
connectivity, which was previously still not working despite fixes in
:ticket:`7871`.

Fixes: #7966
Change-Id: I549ea9e7b6e722e22d3e25bdb2fe0934603e2454

3 years agouse bindparam_type in BinaryElementImpl._post_coercion if available
Mike Bayer [Sun, 1 May 2022 16:28:36 +0000 (12:28 -0400)] 
use bindparam_type in BinaryElementImpl._post_coercion if available

Fixed an issue where using :func:`.bindparam` with no explicit data or type
given could be coerced into the incorrect type when used in expressions
such as when using :meth:`.ARRAY.comparator.any` and
:meth:`.ARRAY.comparator.all`.

Fixes: #7979
Change-Id: If7779e713c9a3a5fee496b66e417cfd3fca5b1f9

3 years agoMerge "Add git-blame-ignore-revs file" into main
mike bayer [Fri, 29 Apr 2022 15:59:40 +0000 (15:59 +0000)] 
Merge "Add git-blame-ignore-revs file" into main

3 years agoMerge "inline mypy config; files ignoring type errors for the moment" into main
mike bayer [Thu, 28 Apr 2022 19:40:46 +0000 (19:40 +0000)] 
Merge "inline mypy config; files ignoring type errors for the moment" into main

3 years agoinline mypy config; files ignoring type errors for the moment
Mike Bayer [Wed, 27 Apr 2022 19:43:02 +0000 (15:43 -0400)] 
inline mypy config; files ignoring type errors for the moment

to simplify pyproject.toml change the remaining files
that aren't going to be typed on this first pass
(unless of course someone wants to type some of these)
to include # mypy: ignore-errors.   for the moment, only a handful
of ORM modules are to have more type checking implemented.

It's important that ignore-errors is used and
not "# type: ignore", as in the latter case, mypy doesn't even
read the existing types in the file, which makes it impossible to
type any files that refer to those modules at all.

to simplify ongoing typing work use inline mypy config
for remaining files that are "done" for now, indicating the
level of type checking they currently have.

Change-Id: I98669c1a305c2f0adba85d10b5425541f3fe9533

3 years agoremove leftover doc from ad11c482e2233f44e8747d4d5a2b17a995fff1fa
Federico Caselli [Wed, 27 Apr 2022 19:50:37 +0000 (21:50 +0200)] 
remove leftover doc from ad11c482e2233f44e8747d4d5a2b17a995fff1fa

Change-Id: I48d6ef0262464350b6ba1a29ce9ba52dea4e25cd

3 years agopep484 ORM / SQL result support
Mike Bayer [Wed, 20 Apr 2022 01:06:41 +0000 (21:06 -0400)] 
pep484 ORM / SQL result support

after some experimentation it seems mypy is more amenable
to the generic types being fully integrated rather than
having separate spin-off types.   so key structures
like Result, Row, Select become generic.  For DML
Insert, Update, Delete, these are spun into type-specific
subclasses ReturningInsert, ReturningUpdate, ReturningDelete,
which is fine since the "row-ness" of these constructs
doesn't happen until returning() is called in any case.

a Tuple based model is then integrated so that these
objects can carry along information about their return
types.  Overloads at the .execute() level carry through
the Tuple from the invoked object to the result.

To suit the issue of AliasedClass generating attributes
that are dynamic, experimented with a custom subclass
AsAliased, but then just settled on having aliased()
lie to the type checker and return `Type[_O]`, essentially.
will need some type-related accessors for with_polymorphic()
also.

Additionally, identified an issue in Update when used
"mysql style" against a join(), it basically doesn't work
if asked to UPDATE two tables on the same column name.
added an error message to the specific condition where
it happens with a very non-specific error message that we
hit a thing we can't do right now, suggest multi-table
update as a possible cause.

Change-Id: I5eff7eefe1d6166ee74160b2785c5e6a81fa8b95

3 years agoAdd git-blame-ignore-revs file
Stephen Finucane [Wed, 27 Apr 2022 12:56:17 +0000 (08:56 -0400)] 
Add git-blame-ignore-revs file

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

### Description

This is helpful when using git-blame on files that 'black' heavily modified back in 2019'ish. While git doesn't specify this name, there seems to be a general convention around using this. See Django [1] and Twisted [2], for example.

[1] https://github.com/django/django/blob/main/.git-blame-ignore-revs
[2] https://github.com/twisted/twisted/blob/trunk/.git-blame-ignore-revs

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [ ] A documentation / typographical 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.
- [x] None of the above
- This is infra-related

**Have a nice day!**

Closes: #7964
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7964
Pull-request-sha: 4be7330a51ee48e360e10a7c5a6d90fea62a9515

Change-Id: I49863f629a64a5320d9d851d1220400fb45dead9

3 years agocherry-pick changelog update for 1.4.37
Mike Bayer [Tue, 26 Apr 2022 21:12:09 +0000 (17:12 -0400)] 
cherry-pick changelog update for 1.4.37

3 years agocherry-pick changelog from 1.4.36
Mike Bayer [Tue, 26 Apr 2022 21:12:08 +0000 (17:12 -0400)] 
cherry-pick changelog from 1.4.36

3 years agoMerge "repair fetch_setting call in mysql pyodbc dialect" into main
mike bayer [Tue, 26 Apr 2022 20:52:08 +0000 (20:52 +0000)] 
Merge "repair fetch_setting call in mysql pyodbc dialect" into main

3 years agochangelog edits for 1.4.36
Mike Bayer [Tue, 26 Apr 2022 19:32:30 +0000 (15:32 -0400)] 
changelog edits for 1.4.36

for 2.0, we split 7953 into two separate changelog files,
one with the 2.0 fix to the logic itself, and the other under
1.4 indicating the warning being emitted.

we also add into 1.4 the file for the C extension change
made for 7875 so it renders into the 1.4 documentation.

Change-Id: I0dd6b8ace355e4884b918484ae7b2c7a8319ff7e
(cherry picked from commit 0c17ba55e695bd71048d750f0dcc24082338444c)

3 years agorepair fetch_setting call in mysql pyodbc dialect
Mike Bayer [Tue, 26 Apr 2022 19:02:37 +0000 (15:02 -0400)] 
repair fetch_setting call in mysql pyodbc dialect

Fixed a regression in the untested MySQL PyODBC dialect caused by the fix
for :ticket:`7518` in version 1.4.32 where an argument was being propagated
incorrectly upon first connect, leading to a ``TypeError``.

Fixes: #7871
Change-Id: I37f8ca8e83cb352ee2a2336b52863858259b1d77

3 years agoforwards port test cases and changelog for #7958 to 2.0
Mike Bayer [Sun, 24 Apr 2022 20:19:16 +0000 (16:19 -0400)] 
forwards port test cases and changelog for #7958 to 2.0

in 6f02d5edd88fe2475629438b0730181a2b00c5fe some cleanup
to ForeignKey repaired the use case of ForeignKey objects
referring to table name alone, by adding more robust
column resolution logic.  This change also fixes an issue
where the "referred column" naming convention key uses the
resolved referred column earlier than usual when a
ForeignKey is setting up its constraint.

change message for 1.4:

Fixed bug where :class:`.ForeignKeyConstraint` naming conventions using the
``referred_column_0`` naming convention key would not work if the foreign
key constraint were set up as a :class:`.ForeignKey` object rather than an
explicit :class:`.ForeignKeyConstraint` object. As this change makes use of
a backport of some fixes from version 2.0, an additional little-known
feature that has likely been broken for many years is also fixed which is
that a :class:`.ForeignKey` object may refer to a referred table by name of
the table alone without using a column name, if the name of the referent
column is the same as that of the referred column.

The ``referred_column_0`` naming convention key was not previously not
tested with the :class:`.ForeignKey` object, only
:class:`.ForeignKeyConstraint`, and this bug reveals that the feature has
never worked correctly unless :class:`.ForeignKeyConstraint` is used for
all FK constraints. This bug traces back to the original introduction of
the feature introduced for :ticket:`3989`.

Fixes: #7958
Change-Id: I230d43e9deba5dff889b9e7fee6cd4d3aa2496d3
(cherry picked from commit e32937fa6a7dcc3d5087aa1f41049373ab9e4038)

3 years agoproperly type array element in any() / all()
Mike Bayer [Fri, 22 Apr 2022 14:57:00 +0000 (10:57 -0400)] 
properly type array element in any() / all()

Fixed bug in :class:`.ARRAY` datatype in combination with :class:`.Enum` on
PostgreSQL where using the ``.any()`` method to render SQL ANY(), given
members of the Python enumeration as arguments, would produce a type
adaptation failure on all drivers.

Fixes: #6515
Change-Id: Ia1e3b4e10aaf264ed436ce6030d105fc60023433

3 years agofix result.columns() method
Mike Bayer [Thu, 21 Apr 2022 17:27:16 +0000 (13:27 -0400)] 
fix result.columns() method

Fixed issue in :meth:`.Result.columns` method where calling upon
:meth:`.Result.columns` with a single index could in some cases,
particularly ORM result object cases, cause the :class:`.Result` to yield
scalar objects rather than :class:`.Row` objects, as though the
:meth:`.Result.scalars` method had been called. In SQLAlchemy 1.4, this
scenario emits a warning that the behavior will change in SQLAlchemy 2.0.

Fixes: #7953
Change-Id: I3c4ca3eecc2bfc85ad1c38000e5990d6dde80d22

3 years agoMerge "Implement UUID.python_type" into main
mike bayer [Thu, 21 Apr 2022 16:55:44 +0000 (16:55 +0000)] 
Merge "Implement UUID.python_type" into main

3 years agoImplement UUID.python_type
Alex Grönholm [Mon, 18 Apr 2022 17:07:19 +0000 (13:07 -0400)] 
Implement UUID.python_type

Implemented :attr:`_postgresql.UUID.python_type` attribute for the
:class:`_postgresql.UUID` type object. The attribute will return either
``str`` or ``uuid.UUID`` based on the :paramref:`_postgresql.UUID.as_uuid`
parameter setting. Previously, this attribute was unimplemented. Pull
request courtesy Alex Grönholm.

Fixes: #7943
Closes: #7944
Change-Id: Ic4fbaeee134d586b08339801968e787cc7e14285

3 years agoMerge "Allow contextvars to be set in events when using asyncio" into main
mike bayer [Thu, 21 Apr 2022 13:44:41 +0000 (13:44 +0000)] 
Merge "Allow contextvars to be set in events when using asyncio" into main

3 years agoFixes minor typo (#7950)
Alex Marvin [Wed, 20 Apr 2022 20:31:38 +0000 (16:31 -0400)] 
Fixes minor typo (#7950)