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

3 years agopep-484: ORM public API, constructors
Mike Bayer [Fri, 15 Apr 2022 15:05:36 +0000 (11:05 -0400)] 
pep-484: ORM public API, constructors

for the moment, abandoning using @overload with
relationship() and mapped_column().  The overloads
are very difficult to get working at all, and
the overloads that were there all wouldn't pass on
mypy.  various techniques of getting them to
"work", meaning having right hand side dictate
what's legal on the left, have mixed success
and wont give consistent results; additionally,
it's legal to have Optional / non-optional
independent of nullable in any case for columns.
relationship cases are less ambiguous but mypy
was not going along with things.

we have a comprehensive system of allowing
left side annotations to drive the right side,
in the absense of explicit settings on the right.
so type-centric SQLAlchemy will be left-side
driven just like dataclasses, and the various flags
and switches on the right side will just not be
needed very much.

in other matters, one surprise, forgot to remove string support
from orm.join(A, B, "somename") or do deprecations
for it in 1.4.   This is a really not-directly-used
structure barely
mentioned in the docs for many years, the example
shows a relationship being used, not a string, so
we will just change it to raise the usual error here.

Change-Id: Iefbbb8d34548b538023890ab8b7c9a5d9496ec6e

3 years agoupdate ORM join doc
Mike Bayer [Tue, 19 Apr 2022 03:12:31 +0000 (23:12 -0400)] 
update ORM join doc

forgot to remove string support for the ON clause here.
will backport a deprecation message to 1.4.

Change-Id: If90e2bff929cce4dc8a6e9bd3ad818b8f8e514a6

3 years agomypy .950 updates
Mike Bayer [Sun, 17 Apr 2022 14:31:48 +0000 (10:31 -0400)] 
mypy .950 updates

Fixes: #7942
Change-Id: Ice1243e1704e88bb8fa13fb0d1f8e24dcd94bfd4

3 years agoAllow contextvars to be set in events when using asyncio
Federico Caselli [Thu, 14 Apr 2022 22:29:01 +0000 (00:29 +0200)] 
Allow contextvars to be set in events when using asyncio

Allow setting contextvar values inside async adapted event handlers.
Previously the value set to the contextvar would not be properly
propagated.

Fixes: #7937
Change-Id: I787aa869f8d057579e13e32c749f05f184ffd02a

3 years agoadapt_from_selectables is a set
Mike Bayer [Sat, 16 Apr 2022 15:40:13 +0000 (11:40 -0400)] 
adapt_from_selectables is a set

aliasedclass setting this as a list, making all the containment
checks more expensive.

the presence of the collection also serves as a flag so it
has to stay optional.

Change-Id: Iafffbeb29d77441ca35ecd8048244ee6eed1232c

3 years agosphinx conf tweaks
Mike Bayer [Fri, 15 Apr 2022 18:22:03 +0000 (14:22 -0400)] 
sphinx conf tweaks

don't put args on the class itself, as it seems
to be using __new__ in some cases which is ugly

get new zzzeeksphinx built

Change-Id: Ib1453646329569eacd282825588292b451a80f68

3 years agoupdate bake_queries documentation
Mike Bayer [Fri, 15 Apr 2022 15:11:42 +0000 (11:11 -0400)] 
update bake_queries documentation

this parameter has had no effect since 1.4.23 in #6889,
but the documentation was not updated.

Change-Id: I36f4ea6144b9fd09243f96698e7a03cd217da1e7
(cherry picked from commit 2ea124b61f0ef98d398c43299509224e9a9d77f6)

3 years agoMerge "pep484: schema API" into main
mike bayer [Fri, 15 Apr 2022 14:58:04 +0000 (14:58 +0000)] 
Merge "pep484: schema API" into main

3 years agopep484: schema API
Mike Bayer [Wed, 13 Apr 2022 13:45:29 +0000 (09:45 -0400)] 
pep484: schema API

implement strict typing for schema.py

this module has lots of public API, lots of old decisions
and very hard to follow construction sequences in many
cases, and is also where we get a lot of new feature requests,
so strict typing should help keep things clean.

among improvements here, fixed the pool .info getters
and also figured out how to get ColumnCollection and
related to be covariant so that we may set them up
as returning Column or ColumnClause without any conflicts.

DDL was affected, noting that superclasses of DDLElement
(_DDLCompiles, added recently) can now be passed into
"ddl_if" callables; reorganized ddl into ExecutableDDLElement
as a new name for DDLElement and _DDLCompiles renamed to
BaseDDLElement.

setting up strict also located an API use case that
is completely broken, which is connection.execute(some_default)
returns a scalar value.   This case has been deprecated
and new paths have been set up so that connection.scalar()
may be used.  This likely wasn't possible in previous
versions because scalar() would assume a CursorResult.

The scalar() change also impacts Session as we have explicit
support (since someone had reported it as a regression)
for session.execute(Sequence()) to work.  They will get the
same deprecation message (which omits the word "Connection",
just uses ".execute()" and ".scalar()") and they can then
use Session.scalar() as well.  Getting this to type
correctly while still supporting ORM use cases required
some refactoring, and I also set up a keyword only delimeter
for Session.execute() and related as execution_options /
bind_arguments should always be keyword only, applied these
changes to AsyncSession as well.

Additionally simpify Table __init__ now that we are Python
3 only, we can have positional plus explicit kwargs finally.
Simplify Column.__init__ as well again taking advantage
of kw only arguments.

Fill in most/all __init__ methods in sqltypes.py as
the constructor for types is most of the API.   should
likely do this for dialect-specific types as well.

Apply _InfoType for all info attributes as should have been
done originally and update descriptor decorators.

Change-Id: I3f9f8ff3f1c8858471ff4545ac83d68c88107527

3 years agoFix link to RFC 1738 (#7935)
Sergey Golitsynskiy [Thu, 14 Apr 2022 20:01:26 +0000 (16:01 -0400)] 
Fix link to RFC 1738 (#7935)

3 years agoEnsure ORMInsert sets up bind state
Mike Bayer [Thu, 14 Apr 2022 16:01:16 +0000 (12:01 -0400)] 
Ensure ORMInsert sets up bind state

Fixed regression where the change in #7861, released in version 1.4.33,
that brought the :class:`.Insert` construct to be partially recognized as
an ORM-enabled statement did not properly transfer the correct mapper /
mapped table state to the :class:`.Session`, causing the
:meth:`.Session.get_bind` method to fail for a :class:`.Session` that was
bound to engines and/or connections using the :paramref:`.Session.binds`
parameter.

Fixes: #7936
Change-Id: If19edef8e2dd68335465429eb3d2f0bfdade4a4c

3 years agoupdate Numeric/Float docstrings
Mike Bayer [Thu, 14 Apr 2022 13:59:11 +0000 (09:59 -0400)] 
update Numeric/Float docstrings

These docs were very out of date re: cdecimal.   Additionally,
as pointed out in #5252, the Numeric documentation is misleading;
SQLAlchemy's Numeric hierarchy resembles more of the Oracle
approach where precision and scale solely determine the kind of
datatype being worked with.   Float is essentially Numeric with
different defaults.

Fixes: #5252
Change-Id: I661109fabf04ba7831c7ddafba15321dd445ea5d

3 years agoMerge "implement multi-element expression constructs" into main
mike bayer [Thu, 14 Apr 2022 12:38:43 +0000 (12:38 +0000)] 
Merge "implement multi-element expression constructs" into main

3 years agoMerge "Fix psycopg2 pre_ping with autocommit" into main
mike bayer [Wed, 13 Apr 2022 21:21:59 +0000 (21:21 +0000)] 
Merge "Fix psycopg2 pre_ping with autocommit" into main

3 years agoimplement multi-element expression constructs
Mike Bayer [Tue, 12 Apr 2022 17:52:31 +0000 (13:52 -0400)] 
implement multi-element expression constructs

Improved the construction of SQL binary expressions to allow for very long
expressions against the same associative operator without special steps
needed in order to avoid high memory use and excess recursion depth. A
particular binary operation ``A op B`` can now be joined against another
element ``op C`` and the resulting structure will be "flattened" so that
the representation as well as SQL compilation does not require recursion.

To implement this more cleanly, the biggest change here is that
column-oriented lists of things are broken away from ClauseList
in a new class ExpressionClauseList, that also forms the basis
of BooleanClauseList. ClauseList is still used for the generic
"comma-separated list" of things such as Tuple and things like
ORDER BY, as well as in some API endpoints.

Also adds __slots__ to the TypeEngine-bound Comparator
classes.   Still can't really do __slots__ on ClauseElement.

Fixes: #7744
Change-Id: I81a8ceb6f8f3bb0fe52d58f3cb42e4b6c2bc9018

3 years agoFix psycopg2 pre_ping with autocommit
Federico Caselli [Mon, 11 Apr 2022 21:19:16 +0000 (23:19 +0200)] 
Fix psycopg2 pre_ping with autocommit

Fixed an issue what would cause autocommit mode to be reset
when using pre_ping in conjunction engine level autocommit
on the psycopg2 driver.

Fixes: #7930
Change-Id: I4cccaf1b7f8cbacd853689458080784114fcc390

3 years agoMerge "read from cls.__dict__ so init_subclass works" into main
mike bayer [Wed, 13 Apr 2022 16:42:29 +0000 (16:42 +0000)] 
Merge "read from cls.__dict__ so init_subclass works" into main

3 years agoread from cls.__dict__ so init_subclass works
Mike Bayer [Mon, 4 Apr 2022 23:01:54 +0000 (19:01 -0400)] 
read from cls.__dict__ so init_subclass works

Modified the :class:`.DeclarativeMeta` metaclass to pass ``cls.__dict__``
into the declarative scanning process to look for attributes, rather than
the separate dictionary passed to the type's ``__init__()`` method. This
allows user-defined base classes that add attributes within an
``__init_subclass__()`` to work as expected, as ``__init_subclass__()`` can
only affect the ``cls.__dict__`` itself and not the other dictionary. This
is technically a regression from 1.3 where ``__dict__`` was being used.

Additionally makes the reference between ClassManager and
the declarative configuration object a weak reference, so that it
can be discarded after mappers are set up.

Fixes: #7900
Change-Id: I3c2fd4e227cc1891aa4bb3d7d5b43d5686f9f27c

3 years agoDon't pass vistor to immutables in cloned traverse
Mike Bayer [Tue, 12 Apr 2022 13:41:55 +0000 (09:41 -0400)] 
Don't pass vistor to immutables in cloned traverse

Saw someone using cloned_traverse to move columns around
(changing their .table) and not surprisingly having poor results.
As cloned traversal is to provide a hook for in-place mutation
of elements, it should not be given Immutable objects as these
should not be changed once they are structurally composed.

Change-Id: I43b22f52f243ef481a75d2cf5ecc73d50f110a81

3 years agopep-484: asyncio
Mike Bayer [Sun, 10 Apr 2022 19:42:35 +0000 (15:42 -0400)] 
pep-484: asyncio

in this patch the asyncio/events.py module, which
existed only to raise errors when trying to attach event
listeners, is removed, as we were already coding an asyncio-specific
workaround in upstream Pool / Session to raise this error,
just moved the error out to the target and did the same thing
for Engine.

We also add an async_sessionmaker class.  The initial rationale
here is because sessionmaker() is hardcoded to Session subclasses,
and there's not a way to get the use case of
sessionmaker(class_=AsyncSession) to type correctly without changing
the sessionmaker() symbol itself to be a function and not a class,
which gets too complicated for what this is. Additionally,
_SessionClassMethods has only three methods on it, one of which
is not usable with asyncio (close_all()), the others
not generally used from the session class.

Change-Id: I064a5fa5d91cc8d5bbe9597437536e37b4e801fe

3 years agopep-484: session, instancestate, etc
Mike Bayer [Thu, 7 Apr 2022 16:37:23 +0000 (12:37 -0400)] 
pep-484: session, instancestate, etc

Also adds some fixes to annotation-based mapping
that have come up, as well as starts to add more
pep-484 test cases

Change-Id: Ia722bbbc7967a11b23b66c8084eb61df9d233fee

3 years agouse code generation for scoped_session
Mike Bayer [Tue, 5 Apr 2022 23:00:19 +0000 (19:00 -0400)] 
use code generation for scoped_session

our decorator thing generates code in any case,
so point it at the file itself to generate real code
for the blocks rather than doing things dynamically.

this will allow typing tools to have no problem
whatsoever and we also reduce import time overhead.
file size will be a lot bigger though, shrugs.

syntax / dupe method / etc. checking will be accomplished
by our existing linting / typing / formatting tools.

As we are also using "from __future__ import annotations",
we also no longer have to apply quotes to generated
annotations.

Change-Id: I20962cb65bda63ff0fb67357ab346e9b1ef4f108

3 years agolevel up pep-484 on engine result
Mike Bayer [Mon, 11 Apr 2022 14:54:42 +0000 (10:54 -0400)] 
level up pep-484 on engine result

Have each result subclass be generic to the
kind of row/object it returns.  rework things so that
a significant number of "type ignores" can go away
and also allow asyncio to more cleanly proxy
the result objects.

Change-Id: Ia3ddb2cb52f5856839bd8c9c46f0289ab4b10405

3 years agorepair ancient and incorrect comment
Mike Bayer [Tue, 12 Apr 2022 02:03:28 +0000 (22:03 -0400)] 
repair ancient and incorrect comment

it referred towards _columntoproperty refering to
lists of MapperProperty.  this comment goes all the
way to pre 0.1 being released.   it's likely been
wrong for nearly all that time.

Change-Id: I71234ae58a6253249d92224356e38372e4aff148

3 years agoupdate flake8 noqa skips with proper syntax
Federico Caselli [Mon, 11 Apr 2022 20:21:20 +0000 (22:21 +0200)] 
update flake8 noqa skips with proper syntax

Change-Id: I42ed77f559e3ee5b8c600d98457ee37803ef0ea6

3 years agosimplify coverage config
Mike Bayer [Sat, 9 Apr 2022 15:32:50 +0000 (11:32 -0400)] 
simplify coverage config

I *think* we don't need to tell .coverage to look in lib,
it seems to be covering from whereever successfuly.  not
sure, but want to run on jenkins to see how it comes out.

Change-Id: Ib74f427a5b09fcbeba0188dcf02dab27c329a8cd

3 years agoadd mypy coverage task
Mike Bayer [Sat, 9 Apr 2022 15:15:29 +0000 (11:15 -0400)] 
add mypy coverage task

get mypy plugin to be able to have coverage

Change-Id: I8c2d57bb97bd522b83d20a0f97576c7ae9ea71a5

3 years agoMerge "add sane_rowcount to SimpleUpdateDeleteTest" into main
mike bayer [Sat, 9 Apr 2022 14:21:28 +0000 (14:21 +0000)] 
Merge "add sane_rowcount to SimpleUpdateDeleteTest" into main

3 years agoupdate DDL examples removing execute_if
Mike Bayer [Sat, 9 Apr 2022 14:02:35 +0000 (10:02 -0400)] 
update DDL examples removing execute_if

Fixes: #7924
Change-Id: I684bf3720010ffe34dbdd39ec8c7e0c4af94e620

3 years agoadd sane_rowcount to SimpleUpdateDeleteTest
Mike Bayer [Sat, 9 Apr 2022 13:50:18 +0000 (09:50 -0400)] 
add sane_rowcount to SimpleUpdateDeleteTest

For third party dialects, repaired a missing requirement for the
``SimpleUpdateDeleteTest`` suite test which was not checking for a working
"rowcount" function on the target dialect.

Fixes: #7919
Change-Id: I2bc68132131eb36c43b8dabec0fac86272e26df5

3 years agoimplement iso date literals for all backends
Mike Bayer [Mon, 28 Mar 2022 17:29:23 +0000 (13:29 -0400)] 
implement iso date literals for all backends

Added modified ISO-8601 rendering (i.e. ISO-8601 with the T converted to a
space) when using ``literal_binds`` with the SQL compilers provided by the
PostgreSQL, MySQL, MariaDB, MSSQL, Oracle dialects. For Oracle, the ISO
format is wrapped inside of an appropriate TO_DATE() function call.
Previously this rendering was not implemented for dialect-specific
compilation.

Fixes: #5052
Change-Id: I7af15a51fedf5c5a8e76e645f7c3be997ece35f0

3 years agoi forgot about begin_nested()
Mike Bayer [Fri, 8 Apr 2022 14:56:54 +0000 (10:56 -0400)] 
i forgot about begin_nested()

make bulleted lists of what is autoflush and what's not.

Change-Id: Id3bc4714013e9df243d804d7b5b60c6ef75e1316

3 years agoclarify autoflush setting does not apply to commit
Mike Bayer [Fri, 8 Apr 2022 14:36:50 +0000 (10:36 -0400)] 
clarify autoflush setting does not apply to commit

Change-Id: Icad0f3bd071422b8d1af204c9a1193a9ce6124ba
References: #7916

3 years agoupdate comment re: #2703
Mike Bayer [Fri, 8 Apr 2022 13:48:26 +0000 (09:48 -0400)] 
update comment re: #2703

Change-Id: Ia78db7601e98acd2562872e0fda639aac99650dd

3 years agoexplicitly refer to Apple M1 for greenlet issue
Mike Bayer [Fri, 8 Apr 2022 13:28:47 +0000 (09:28 -0400)] 
explicitly refer to Apple M1 for greenlet issue

As developers are now buying lots of Apple M1
machines, and AFAWK greenlet is still not able
to provide a pre-built wheel, we are going to get a lot
of devs trying to use asyncio on their Apple M1s, in
greater proportions compared to devs running containers
etc. on other various less popular CPU architectures.

Add a new FAQ section for installation, add new
red dragon to the very top of asyncio docs,
add new verbiage, all of which includes
"Apple M1" in bold text, to minimize the chance of anyone
missing this.

Fixes: #7922
Fixes: #7714
Change-Id: I106923a2860a4efd77d1b999197be102afc1f73d

3 years agoMerge "cx_Oracle modernize" into main
mike bayer [Thu, 7 Apr 2022 15:19:10 +0000 (15:19 +0000)] 
Merge "cx_Oracle modernize" into main