]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/log
thirdparty/sqlalchemy/sqlalchemy.git
3 years agoimprove custom operator for SQL types docs
Mike Bayer [Tue, 4 Jan 2022 19:08:10 +0000 (14:08 -0500)] 
improve custom operator for SQL types docs

introduce here that "custom ops" first come from
the .op() method in the usual case.  then only if one wants
such an op to be pre-assocaited with particular types,
then the comparator may be used.  Also clarify the individual
points regarding the comparator.

Change-Id: Id6046448eb2c17fa6e3f2ef6d9343b156ddec96f

3 years agoadjust TypeError message yet again
Mike Bayer [Sat, 1 Jan 2022 21:50:41 +0000 (16:50 -0500)] 
adjust TypeError message yet again

in 924d38e660981ae2a7d55355603 we got it almost right in
all cases, Pypy seems to have an entirely different kind of message
so make this much more open ended.

Change-Id: I661a9ee0cf8247d715e35f8b9188cd1ac46abdfb

3 years agoadjust error message assertion for TypeError
Mike Bayer [Sat, 1 Jan 2022 20:30:15 +0000 (15:30 -0500)] 
adjust error message assertion for TypeError

in eee7a3add99df2865e6d907f2 I added a few TypeError
tests, and some python interpreters produce a message like
"join() got an unexpected...", others seem to produce
"Query.join() got an unexpected..."

the pattern is strange, all Python 3.10's seem to return the
class name.  For Python 3.8 and 3.9, my local intepreters
are doing the Python 3.10 behavior but github actions are doing
the older behavior.  Python 3.7 both here and on github actions
are doing the older behavior.

In any case, adjust the regexps to match both.

Change-Id: I3ab13e2be51ab243f8f6bcecf26fd03070cec17f

3 years agoremove 2.0-removed Query elements
Mike Bayer [Thu, 30 Dec 2021 00:26:08 +0000 (19:26 -0500)] 
remove 2.0-removed Query elements

* :meth:`_orm.Query.join` no longer accepts the "aliased" and
"from_joinpoint" arguments

* :meth:`_orm.Query.join` no longer accepts chains of multiple join
targets in one method call.

* ``Query.from_self()`` and ``Query.with_polymorphic()``
are removed.

Change-Id: I534d04b53a538a4fc374966eb2bc8eb98a16497d
References: #7257

3 years agoProperly type _generative, decorator, public_factory
Federico Caselli [Wed, 22 Dec 2021 20:45:45 +0000 (21:45 +0100)] 
Properly type _generative, decorator, public_factory

Good new is that pylance likes it and copies over the
singature and everything.
Bad news is that mypy does not support this yet https://github.com/python/mypy/issues/8645
Other minor bad news is that non_generative is not typed. I've tried using a protocol
like the one in the comment but the signature is not ported over by pylance, so it's
probably best to just live without it to have the correct signature.

notes from mike:  these three decorators are at the core of getting
the library to be typed, more good news is that pylance will
do all the things we like re: public_factory, see
https://github.com/microsoft/pyright/issues/2758#issuecomment-1002788656
.

For @_generative, we will likely move to using pep 673 once mypy
supports it which may be soon.  but overall having the explicit
"return self" in the methods, while a little inconvenient, makes
the typing more straightforward and locally present in the files
rather than being decided at a distance.   having "return self"
present, or not, both have problems, so maybe we will be able
to change it again if things change as far as decorator support.
As it is, I feel like we are barely squeaking by with our decorators,
the typing is already pretty out there.

Change-Id: Ic77e13fc861def76a5925331df85c0aa48d77807
References: #6810

3 years agoMerge "remove legacy select patterns" into main
mike bayer [Wed, 29 Dec 2021 19:19:42 +0000 (19:19 +0000)] 
Merge "remove legacy select patterns" into main

3 years agoremove legacy select patterns
Mike Bayer [Wed, 29 Dec 2021 17:10:23 +0000 (12:10 -0500)] 
remove legacy select patterns

Change-Id: If6e521a1eb461e08748a0432943b938528a2619e
References: #7257

3 years agoreplace Variant with direct feature inside of TypeEngine
Mike Bayer [Sat, 23 Oct 2021 15:26:45 +0000 (11:26 -0400)] 
replace Variant with direct feature inside of TypeEngine

The :meth:`_sqltypes.TypeEngine.with_variant` method now returns a copy of
the original :class:`_sqltypes.TypeEngine` object, rather than wrapping it
inside the ``Variant`` class, which is effectively removed (the import
symbol remains for backwards compatibility with code that may be testing
for this symbol). While the previous approach maintained in-Python
behaviors, maintaining the original type allows for clearer type checking
and debugging.

Fixes: #6980
Change-Id: I158c7e56306b886b5b82b040205c428a5c4a242c

3 years agouse long long for id() result
Mike Bayer [Tue, 28 Dec 2021 15:54:18 +0000 (10:54 -0500)] 
use long long for id() result

per https://stackoverflow.com/a/27055236/34549 apparently there
is "long long" in cython.

Change-Id: I08bfaaccbf87ec9a2dc0d4b154f9c9d454171342

3 years agoMerge "Reflect included columns as dialect_options" into main
mike bayer [Mon, 27 Dec 2021 22:07:10 +0000 (22:07 +0000)] 
Merge "Reflect included columns as dialect_options" into main

3 years agoMerge "Replace raise_ with raise from" into main
Federico Caselli [Mon, 27 Dec 2021 21:04:54 +0000 (21:04 +0000)] 
Merge "Replace raise_ with raise from" into main

3 years agoReplace raise_ with raise from
Federico Caselli [Sat, 18 Dec 2021 10:11:49 +0000 (11:11 +0100)] 
Replace raise_ with raise from

Change-Id: I7aaeb5bc130271624335b79cf586581d6c6c34c7
References: #4600

3 years agoReflect included columns as dialect_options
Gord Thompson [Mon, 20 Dec 2021 21:37:13 +0000 (14:37 -0700)] 
Reflect included columns as dialect_options

Fixed reflection of covering indexes to report ``include_columns`` as part
of the ``dialect_options`` entry in the reflected index dictionary, thereby
enabling round trips from reflection->create to be complete. Included
columns continue to also be present under the ``include_columns`` key for
backwards compatibility.

Fixes: #7382
Change-Id: I4f16b65caed3a36d405481690a3a92432b5efd62

3 years agoMerge "propose concurrency check for SessionTransaction" into main
mike bayer [Mon, 27 Dec 2021 19:20:10 +0000 (19:20 +0000)] 
Merge "propose concurrency check for SessionTransaction" into main

3 years agoMerge "cursor tweaks" into main
mike bayer [Mon, 27 Dec 2021 19:15:40 +0000 (19:15 +0000)] 
Merge "cursor tweaks" into main

3 years agoMerge "factor out UnboundLoad and rearchitect strategy_options.py" into main
mike bayer [Mon, 27 Dec 2021 18:14:31 +0000 (18:14 +0000)] 
Merge "factor out UnboundLoad and rearchitect strategy_options.py" into main

3 years agopropose concurrency check for SessionTransaction
Mike Bayer [Thu, 2 Dec 2021 14:18:11 +0000 (09:18 -0500)] 
propose concurrency check for SessionTransaction

the discussion at #7387 refers to a condition that seems
to happen in the wild also, such as [1] [2] [3], it's not
entirely clear why this specific spot is how this occurs,
however it's maybe that when the connection is being acquired
from the pool, under load there might be a wait on the connection
pool, leading to more time for another errant thread to be
calling .close(), just a theory.

in this patch we propose using decorators and context managers
along with declarative state declarations to block reentrant
or concurrent calls to methods that conflict with expected
state changes.

The :class:`_orm.Session` (and by extension :class:`.AsyncSession`) now has
new state-tracking functionality that will proactively trap any unexpected
state changes which occur as a particular transactional method proceeds.
This is to allow situations where the :class:`_orm.Session` is being used
in a thread-unsafe manner, where event hooks or similar may be calling
unexpected methods within operations, as well as potentially under other
concurrency situations such as asyncio or gevent to raise an informative
message when the illegal access first occurs, rather than passing silently
leading to secondary failures due to the :class:`_orm.Session` being in an
invalid state.

[1] https://stackoverflow.com/questions/25768428/sqlalchemy-connection-errors
[2] https://groups.google.com/g/sqlalchemy/c/n5oVX3v4WOw
[3] https://github.com/cosmicpython/code/issues/23

Fixes: #7433
Change-Id: I699b935c0ec4e5a63f12cf878af6f7a92a30a3aa

3 years agofactor out UnboundLoad and rearchitect strategy_options.py
Mike Bayer [Thu, 9 Dec 2021 01:27:16 +0000 (20:27 -0500)] 
factor out UnboundLoad and rearchitect strategy_options.py

The architecture of Load is mostly rewritten here.

The change includes removal of the "pluggable" aspect
of the loader options, which would patch new methods onto
Load.  This has been replaced by normal methods that
respond normally to typing annotations.  As part of this
change, the bake_loaders() and unbake_loaders() options,
which have no effect since 1.4 and were unlikely to be
in any common use, have been removed.

Additionally, to support annotations for methods that
make use of @decorator, @generative etc., modified
format_argspec_plus to no longer return "args", instead
returns "grouped_args" which is always grouped and
allows return annotations to format correctly.

Fixes: #6986
Change-Id: I6117c642345cdde65a64389bba6057ddd5374427

3 years agocursor tweaks
Mike Bayer [Sat, 25 Dec 2021 04:11:23 +0000 (23:11 -0500)] 
cursor tweaks

tighten up creation of dictionaries and conditional logic
within the creation of CursorResultMetaData objects

Change-Id: I5538ecc343ab0cabcf58d7c92ae0a552d5ac1d8a

3 years agoMerge "consider truediv as truediv; support floordiv operator" into main
mike bayer [Mon, 27 Dec 2021 16:29:23 +0000 (16:29 +0000)] 
Merge "consider truediv as truediv; support floordiv operator" into main

3 years agoMerge "implement cython for cache_anon_map, prefix_anon_map" into main
mike bayer [Mon, 27 Dec 2021 15:26:31 +0000 (15:26 +0000)] 
Merge "implement cython for cache_anon_map, prefix_anon_map" into main

3 years agoconsider truediv as truediv; support floordiv operator
Mike Bayer [Wed, 8 Dec 2021 13:57:44 +0000 (08:57 -0500)] 
consider truediv as truediv; support floordiv operator

Implemented full support for "truediv" and "floordiv" using the
"/" and "//" operators.  A "truediv" operation between two expressions
using :class:`_types.Integer` now considers the result to be
:class:`_types.Numeric`, and the dialect-level compilation will cast
the right operand to a numeric type on a dialect-specific basis to ensure
truediv is achieved.  For floordiv, conversion is also added for those
databases that don't already do floordiv by default (MySQL, Oracle) and
the ``FLOOR()`` function is rendered in this case, as well as for
cases where the right operand is not an integer (needed for PostgreSQL,
others).

The change resolves issues both with inconsistent behavior of the
division operator on different backends and also fixes an issue where
integer division on Oracle would fail to be able to fetch a result due
to inappropriate outputtypehandlers.

Fixes: #4926
Change-Id: Id54cc018c1fb7a49dd3ce1216d68d40f43fe2659

3 years agoMerge "include empty intermediary tables in optimized get" into main
mike bayer [Mon, 27 Dec 2021 00:24:24 +0000 (00:24 +0000)] 
Merge "include empty intermediary tables in optimized get" into main

3 years agoinclude empty intermediary tables in optimized get
Mike Bayer [Sun, 26 Dec 2021 17:13:19 +0000 (12:13 -0500)] 
include empty intermediary tables in optimized get

Fixed issue in joined-inheritance load of additional attributes
functionality in deep multi-level inheritance where an intermediary table
that contained no columns would not be included in the tables joined,
instead linking those tables to their primary key identifiers. While this
works fine, it nonetheless in 1.4 began producing the cartesian product
compiler warning. The logic has been changed so that these intermediary
tables are included regardless. While this does include additional tables
in the query that are not technically necessary, this only occurs for the
highly unusual case of deep 3+ level inheritance with intermediary tables
that have no non primary key columns, potential performance impact is
therefore expected to be negligible.

Fixes: #7507
Change-Id: Id2073773e97a0853b744b51feeb2bc4437032e51

3 years agorestore graceful degrade of subqueryload w from_statement
Mike Bayer [Sun, 26 Dec 2021 16:25:00 +0000 (11:25 -0500)] 
restore graceful degrade of subqueryload w from_statement

Fixed regression from 1.3 where the "subqueryload" loader strategy would
fail with a stack trace if used against a query that made use of
:meth:`_orm.Query.from_statement` or :meth:`_sql.Select.from_statement`. As
subqueryload requires modifying the original statement, it's not compatible
with the "from_statement" use case, especially for statements made against
the :func:`_sql.text` construct. The behavior now is equivalent to that of
1.3 and previously, which is that the loader strategy silently degrades to
not be used for such statements, typically falling back to using the
lazyload strategy.

Fixes: #7505
Change-Id: I950800dc86a77f8320a5e696edce1ff2c84b1eb9

3 years agocherry-pick changelog update for 1.4.30
Mike Bayer [Thu, 23 Dec 2021 02:19:30 +0000 (21:19 -0500)] 
cherry-pick changelog update for 1.4.30

3 years agocherry-pick changelog from 1.4.29
Mike Bayer [Thu, 23 Dec 2021 02:19:29 +0000 (21:19 -0500)] 
cherry-pick changelog from 1.4.29

3 years agoadd mariadb conf section
Mike Bayer [Thu, 23 Dec 2021 02:07:33 +0000 (21:07 -0500)] 
add mariadb conf section

Change-Id: I7686ab7a877895de33e9ca19217ae38cb5729238

3 years agoMerge "add recursion check for with_loader_criteria() option" into main
mike bayer [Thu, 23 Dec 2021 00:38:36 +0000 (00:38 +0000)] 
Merge "add recursion check for with_loader_criteria() option" into main

3 years agoFix missing class attributes when using __class_getitem__
Kai Mueller [Tue, 21 Dec 2021 20:00:30 +0000 (15:00 -0500)] 
Fix missing class attributes when using __class_getitem__

Fixed issue where the ``__class_getitem__()`` method of the generated
declarative base class by :func:`_orm.as_declarative` would lead to
inaccessible class attributes such as ``__table__``, for cases where a
``Generic[T]`` style typing declaration were used in the class hierarchy.
This is in continuation from the basic addition of ``__class_getitem__()``
in :ticket:`7368`. Pull request courtesy Kai Mueller.

Fixes: #7462
Closes: #7470
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7470
Pull-request-sha: d5e5765e0e5542149f116ed9ccff1b3e2e32dee5

Change-Id: I6418af6d34532ff181343884bd419d9c2684e617

3 years agouse fully qualified, locatable names for all use of api.named_type()
Mike Bayer [Wed, 22 Dec 2021 21:21:33 +0000 (16:21 -0500)] 
use fully qualified, locatable names for all use of api.named_type()

Fixed mypy regression where the release of mypy 0.930 added additional
internal checks to the format of "named types", requiring that they be
fully qualified and locatable. This broke the mypy plugin for SQLAlchemy,
raising an assertion error, as there was use of symbols such as
``__builtins__`` and other un-locatable or unqualified names that
previously had not raised any assertions.

Fixes: #7496
Change-Id: I037680606a1d51158ef6503508ec76c5d5adc946

3 years agoadd recursion check for with_loader_criteria() option
Mike Bayer [Wed, 22 Dec 2021 20:33:11 +0000 (15:33 -0500)] 
add recursion check for with_loader_criteria() option

Fixed recursion overflow which could occur within ORM statement compilation
when using either the :func:`_orm.with_loader_criteria` feature or the the
:meth:`_orm.PropComparator.and_` method within a loader strategy in
conjunction with a subquery which referred to the same entity being altered
by the criteria option, or loaded by the loader strategy.  A check for
coming across the same loader criteria option in a recursive fashion has
been added to accommodate for this scenario.

Fixes: #7491
Change-Id: I8701332717c45a21948ea4788a3058c0fbbf03a7

3 years agoMerge "remove all python_version<3 specs; update pytest" into main
mike bayer [Wed, 22 Dec 2021 19:32:59 +0000 (19:32 +0000)] 
Merge "remove all python_version<3 specs; update pytest" into main

3 years agoremove duplicate Load doc
Mike Bayer [Wed, 22 Dec 2021 17:37:50 +0000 (12:37 -0500)] 
remove duplicate Load doc

this is already in loading_relationships where it's more
directly discussed.

Change-Id: I78908cd3f4508ff0c8ee33fbc0829780366e82f1

3 years agoremove all python_version<3 specs; update pytest
Mike Bayer [Wed, 22 Dec 2021 14:45:38 +0000 (09:45 -0500)] 
remove all python_version<3 specs; update pytest

pytest 7 is on rc, so in order to get it installed
when I run tox, bump min version to 7.0.0rc1. The performance
issues with version 6 are not tolerable.

Additionally remove all python_version<3.7 specs from setup.cfg,
tox, these are no longer needed.

Change-Id: Id5523bc920c562a9c2a59aba51a36dda3b11a079

3 years agoaccommodate for "clone" of ColumnClause
Mike Bayer [Tue, 21 Dec 2021 23:08:33 +0000 (18:08 -0500)] 
accommodate for "clone" of ColumnClause

for use with the ClauseElement.params() method,
altered ColumnClause._clone() so that while the element
stays immutable, if the column is associated with a subquery,
it returns a new version of itself as corresponding to a
clone of the subquery.  this allows processing functions
to access the parameters in the subquery and produce a
copy of it.  The use case here is the expanded use of
.params() within loader strategies that use
HasCacheKey._apply_params_to_element().

Fixed issue in new "loader criteria" method
:meth:`_orm.PropComparator.and_` where usage with a loader strategy like
:func:`_orm.selectinload` against a column that was a member of the ``.c.``
collection of a subquery object, where the subquery would be dynamically
added to the FROM clause of the statement, would be subject to stale
parameter values within the subquery in the SQL statement cache, as the
process used by the loader strategy to replace the parameters at execution
time would fail to accommodate the subquery when received in this form.

Fixes: #7489
Change-Id: Ibb3b6af140b8a62a2c8d05b2ac92e86ca3013c46

3 years agoimplement cython for cache_anon_map, prefix_anon_map
Mike Bayer [Sun, 19 Dec 2021 20:59:55 +0000 (15:59 -0500)] 
implement cython for cache_anon_map, prefix_anon_map

These are small bits where cache_anon_map in particular
is part of the cache key generation scheme which is a key
target for cython.

changing such a tiny element of the cache key gen is
doing basically nothing yet, as the cython impl is
mostly the exact same speed as the python one.  I guess for
cython to be effective we'd need to redo the whole cache key
generation and possibly not use the same kinds of structures,
which might not be very easy to do.

Additionally, some cython runtime import errors are being
observed on jenkins, add an upfront check to the test suite
to indicate if the expected build succeeded when REQUIRE_SQLALCHEMY_CEXT
is set.

Running case CacheAnonMap
Running python .... Done
Running cython .... Done
                    | python      | cython      | cy / py     |
test_get_anon_non_present| 0.301266758 | 0.231203834 | 0.767438915 |
test_get_anon_present| 0.300919362 | 0.227336695 | 0.755473803 |
test_has_key_non_present| 0.152725077 | 0.133191719 | 0.872101171 |
test_has_key_present| 0.152689778 | 0.133673095 | 0.875455428 |
Running case PrefixAnonMap
Running python .. Done
Running cython .. Done
                    | python      | cython      | cy / py     |
test_apply_non_present| 0.358715744 | 0.335245703 | 0.934572034 |
test_apply_present  | 0.354434996 | 0.338579782 | 0.955266229 |

Change-Id: I0d3f1dd285c044afc234479141d831b2ee0455be

3 years agoMerge "use load_scalar_attributes() for undefer" into main
mike bayer [Mon, 20 Dec 2021 14:09:27 +0000 (14:09 +0000)] 
Merge "use load_scalar_attributes() for undefer" into main

3 years agouse load_scalar_attributes() for undefer
Mike Bayer [Wed, 15 Dec 2021 20:00:28 +0000 (15:00 -0500)] 
use load_scalar_attributes() for undefer

At some point, undeferral of attributes started emitting
a full ORM query for the entity, including that subclass columns
would use a JOIN.   Seems to be at least in 1.3 / 1.4 and possibly
earlier.    This JOINs to the superclass table unnecessarily.
Use load_scalar_attributes() here which should handle the whole
thing and emits a more efficient query for joined inheritance.

As this behavior seems to have been throughout 1.3 and 1.4
at least, targeting at 2.0 is likely best.

Fixes: #7463
Change-Id: Ie4bae767747bba0d03fb13eaff579d4bab0b1bc2

3 years agoupdate changelog / migration / intro for cython
Mike Bayer [Sat, 18 Dec 2021 17:36:21 +0000 (12:36 -0500)] 
update changelog / migration / intro for cython

also detail pep-517 changes

Change-Id: Ia8b3ffbe5ad222d22fe199077daa49e3f9d8e2a0

3 years agoReplace c extension with cython versions. 7474/head
Federico Caselli [Fri, 1 Jan 2021 15:09:01 +0000 (16:09 +0100)] 
Replace c extension with cython versions.

Re-implement c version immutabledict / processors / resultproxy / utils with cython.
Performance is in general in par or better than the c version
Added a collection module that has cython version of OrderedSet and IdentitySet

Added a new test/perf file to compare the implementations.
Run ``python test/perf/compiled_extensions.py all`` to execute the comparison test.

See results here: https://docs.google.com/document/d/1nOcDGojHRtXEkuy4vNXcW_XOJd9gqKhSeALGG3kYr6A/edit?usp=sharing

Fixes: #7256
Change-Id: I2930ef1894b5048210384728118e586e813f6a76
Signed-off-by: Federico Caselli <cfederico87@gmail.com>
3 years agoMerge "include InterfaceError for mariadb disconnect check" into main
mike bayer [Thu, 16 Dec 2021 16:08:33 +0000 (16:08 +0000)] 
Merge "include InterfaceError for mariadb disconnect check" into main

3 years agoinclude InterfaceError for mariadb disconnect check
Mike Bayer [Tue, 14 Dec 2021 21:46:50 +0000 (16:46 -0500)] 
include InterfaceError for mariadb disconnect check

Corrected the error classes inspected for the "is_disconnect" check for the
``mariadbconnector`` dialect, which was failing for disconnects that
occurred due to common MySQL/MariaDB error codes such as 2006; the DBAPI
appears to currently use the ``mariadb.InterfaceError`` exception class for
disconnect errors such as error code 2006, which has been added to the list
of classes checked.

For the current "real reconnect test", shutting down the mariadb
connection from the client side produces
ProgrammingError("Connection isn't valid anymore") which we also
continue to intercept.

Fixes: #7457
Change-Id: I0b37cd7a73359a23ad756ff2af0a9333c841221b

3 years agorestore psycopg changelog file
Mike Bayer [Wed, 15 Dec 2021 21:33:40 +0000 (16:33 -0500)] 
restore psycopg changelog file

this file was removed from 1.4 as part of
3b6a68b.  as this is a 2.0 only change, restore it there.

Change-Id: Idd7081d9e09b4b725283b4a7965ee37fd169eac8
References: #6842

3 years agobump psycopg to 3.0.7
Mike Bayer [Wed, 15 Dec 2021 03:20:08 +0000 (22:20 -0500)] 
bump psycopg to 3.0.7

revert the change from 893b4e03921eb1a86e202988bf247251d0d2fae9
and set lower bound for psycopg to 3.0.7

Change-Id: If506c6c3190c4d40683a10ddaea32a417e9c6ed4
References: https://github.com/psycopg/psycopg/issues/178

3 years agoIgnore ephemeral classes in test_all_present()
Nils Philippsen [Sun, 12 Dec 2021 23:35:03 +0000 (18:35 -0500)] 
Ignore ephemeral classes in test_all_present()

Fixed a regression in the test suite where the test called
``CompareAndCopyTest::test_all_present`` would fail on some platforms due
to additional testing artifacts being detected. Pull request courtesy Nils
Philippsen.

In some circumstances, ephemeral class objects that are created within
the scope of a test method don't seem to be garbage collected directly
on exit. Filter out classes created in test modules.

Fixes: #7450
Closes: #7451
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7451
Pull-request-sha: 135a8aaba2c6941460c7f45aa1a55c8f6b9eb43d

Change-Id: I621967bd916089dc1e3f98625fd2a852cd9fd712

3 years agoskip rowcount test for psycopg
Mike Bayer [Tue, 14 Dec 2021 20:44:39 +0000 (15:44 -0500)] 
skip rowcount test for psycopg

psycopg is failing to report correct rowcount for this
test against PostgreSQL 14 only as of psycopg 3.0.5 or 3.0.6;
works in 3.0.4

skip test until a report can be filed w/ psycopg

Change-Id: I6a0b8c26314a9e451a1c93c3e48665c650115982

3 years agoMerge "implement correct errors for Row immutability" into main
mike bayer [Sun, 12 Dec 2021 23:29:11 +0000 (23:29 +0000)] 
Merge "implement correct errors for Row immutability" into main

3 years agouse the options from the cached statement for propagate_options
Mike Bayer [Sun, 12 Dec 2021 18:37:21 +0000 (13:37 -0500)] 
use the options from the cached statement for propagate_options

Fixed caching-related issue where the use of a loader option of the form
``lazyload(aliased(A).bs).joinedload(B.cs)`` would fail to result in the
joinedload being invoked for runs subsequent to the query being cached, due
to a mismatch for the options / object path applied to the objects loaded
for a query with a lead entity that used ``aliased()``.

Fixes: #7447
Change-Id: I4e9c34654b7d3668cd8878decbd688afe2af5f81

3 years agoFix referenced ticket number (#7439)
Nils Philippsen [Sat, 11 Dec 2021 16:24:22 +0000 (17:24 +0100)] 
Fix referenced ticket number (#7439)

Signed-off-by: Nils Philippsen <nils@tiptoe.de>
3 years agoMerge "Add execution options to ``Session.get``" into main
Federico Caselli [Sat, 11 Dec 2021 08:09:20 +0000 (08:09 +0000)] 
Merge "Add execution options to ``Session.get``" into main

3 years agoMerge "Add async_engine_from_config()" into main
Federico Caselli [Sat, 11 Dec 2021 08:08:04 +0000 (08:08 +0000)] 
Merge "Add async_engine_from_config()" into main

3 years agoMerge "Add ``scalars`` to Migration - ORM Usage table." into main
mike bayer [Fri, 10 Dec 2021 16:24:21 +0000 (16:24 +0000)] 
Merge "Add ``scalars`` to Migration - ORM Usage table." into main

3 years agoMerge "Removals: strings for join(), loader_options()." into main
mike bayer [Fri, 10 Dec 2021 16:21:09 +0000 (16:21 +0000)] 
Merge "Removals: strings for join(), loader_options()." into main

3 years agoAdd async_engine_from_config()
Nils Philippsen [Sat, 13 Nov 2021 16:11:32 +0000 (11:11 -0500)] 
Add async_engine_from_config()

Added :func:`_asyncio.async_engine_config` function to create
an async engine from a configuration dict.  This otherwise
behaves the same as :func:`_sa.engine_from_config`.

Fixes: #7301
Closes: #7302
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7302
Pull-request-sha: c7c758833b6c37b7509b8c5bed4f26ac0ccc0395

Change-Id: I64feadf95b5015c24fe0fa0dbae6755b72d1713e

3 years agoAdd execution options to ``Session.get``
Federico Caselli [Thu, 9 Dec 2021 21:11:37 +0000 (22:11 +0100)] 
Add execution options to ``Session.get``

Fixes: #7410
Change-Id: Iab6427b8b4c2ada8c31ef69f92d27c1185dbb6b1

3 years agoMerge branch 'postgresql-docs-update-table-numbers' into main_gerrit
Federico Caselli [Fri, 10 Dec 2021 13:27:30 +0000 (14:27 +0100)] 
Merge branch 'postgresql-docs-update-table-numbers' into main_gerrit

Change-Id: Iac125101206ac78fb8344fd190b05e3d41151eee

3 years agoUpdate references to tables in PostgreSQL documentation
Leo Singer [Fri, 8 Oct 2021 02:07:08 +0000 (22:07 -0400)] 
Update references to tables in PostgreSQL documentation

Since the table numbers change from one version of PostgreSQL to
the next, refer to the tables by name rather than by number.

3 years agoAdd ``scalars`` to Migration - ORM Usage table.
Federico Caselli [Thu, 9 Dec 2021 21:41:47 +0000 (22:41 +0100)] 
Add ``scalars`` to Migration - ORM Usage table.

Fixes #7407

Change-Id: I0ec7c0dd44dce3b907296824ee4e6103bc72a6dd

3 years agoInclude import error message when greenlet is not installed
Federico Caselli [Thu, 9 Dec 2021 20:47:22 +0000 (21:47 +0100)] 
Include import error message when greenlet is not installed

Fixes: #7419
Change-Id: I0c604875a80287acff3bab732f67601a5e2db98c

3 years agocherry-pick changelog update for 1.4.29
Mike Bayer [Thu, 9 Dec 2021 19:50:37 +0000 (14:50 -0500)] 
cherry-pick changelog update for 1.4.29

3 years agocherry-pick changelog from 1.4.28
Mike Bayer [Thu, 9 Dec 2021 19:50:36 +0000 (14:50 -0500)] 
cherry-pick changelog from 1.4.28

3 years agoMerge branch 'typos-fixes' into main_gerrit
Federico Caselli [Thu, 9 Dec 2021 19:24:38 +0000 (20:24 +0100)] 
Merge branch 'typos-fixes' into main_gerrit

Change-Id: I32a4c97add07a3fe7d2d5cc4f1cd263b2042e123

3 years agoimplement correct errors for Row immutability
Mike Bayer [Thu, 9 Dec 2021 19:23:42 +0000 (14:23 -0500)] 
implement correct errors for Row immutability

Corrected the error message for the ``AttributeError`` that's raised when
attempting to write to an attribute on the :class:`_result.Row` class,
which is immutable. The previous message claimed the column didn't exist
which is misleading.

Fixes: #7432
Change-Id: If0e2cbd3f763dca6c99a18aa42252c69f1207d59

3 years agoimplement attributes.Proxy._clone()
Mike Bayer [Thu, 9 Dec 2021 17:51:43 +0000 (12:51 -0500)] 
implement attributes.Proxy._clone()

Fixed issue where the internal cloning used by the
:meth:`_orm.PropComparator.any` method on a :func:`_orm.relationship` in
the case where the related class also makes use of ORM polymorphic loading,
would fail if a hybrid property on the related, polymorphic class were used
within the criteria for the ``any()`` operation.

Fixes: #7425
Change-Id: I5f4f4ec5fab17df228bc6e3de412d24114b20600

3 years agochangelog updates
Mike Bayer [Thu, 9 Dec 2021 17:36:25 +0000 (12:36 -0500)] 
changelog updates

Change-Id: Ie136cfb7375e68b2badba1099b5b041f99da85fa

3 years agoFix typo in docstring 7417/head
Lele Gaifax [Thu, 9 Dec 2021 07:14:06 +0000 (08:14 +0100)] 
Fix typo in docstring

3 years agoFix typo in changelog
Lele Gaifax [Thu, 9 Dec 2021 07:13:42 +0000 (08:13 +0100)] 
Fix typo in changelog

3 years agoRemovals: strings for join(), loader_options().
Mike Bayer [Wed, 8 Dec 2021 19:19:11 +0000 (14:19 -0500)] 
Removals: strings for join(), loader_options().

* The :meth:`_orm.Query.join` method no longer accepts strings for
relationship names; the long-documented approach of using
``Class.attrname`` for join targets is now standard.

* Loader options no longer accept strings for attribute names.  The
long-documented approach of using ``Class.attrname`` for loader option
targets is now standard.

It is hoped that a subsequent commit can refactor loader
options to no longer need "UnboundLoad" for most cases.

Change-Id: If4629882c40523dccbf4459256bf540fb468b618
References: #6986

3 years agoinclude correct notes for 2.0
Mike Bayer [Wed, 8 Dec 2021 18:55:32 +0000 (13:55 -0500)] 
include correct notes for 2.0

the changelog_20 file either started out wrong
or got changed at some point to include the wrong change notes,
so the unreleased_20/ notes were not being displayed.

Change-Id: Iecb0db86ba5c6bacf4f8fdf8876dc411f357d6df

3 years agoMerge "Warn when caching is disabled / document" into main
mike bayer [Tue, 7 Dec 2021 15:46:54 +0000 (15:46 +0000)] 
Merge "Warn when caching is disabled / document" into main

3 years agoMerge "contextmanager skips rollback if trans says to skip it" into main
mike bayer [Tue, 7 Dec 2021 14:52:55 +0000 (14:52 +0000)] 
Merge "contextmanager skips rollback if trans says to skip it" into main

3 years agoMerge "Add __copy__, __deepcopy__ to URL. Fixes: #7400" into main
mike bayer [Mon, 6 Dec 2021 23:29:11 +0000 (23:29 +0000)] 
Merge "Add __copy__, __deepcopy__ to URL. Fixes: #7400" into main

3 years agoWarn when caching is disabled / document
Mike Bayer [Fri, 3 Dec 2021 19:04:05 +0000 (14:04 -0500)] 
Warn when caching is disabled / document

This patch adds new warnings for all elements that
don't indicate their caching behavior, including user-defined
ClauseElement subclasses and third party dialects.
it additionally adds new documentation to discuss an apparent
performance degradation in 1.4 when caching is disabled as a
result in the significant expense incurred by ORM
lazy loaders, which in 1.3 used BakedQuery so were actually
cached.

As a result of adding the warnings, a fair degree of
lesser used SQL expression objects identified that they did not
define caching behavior so would have been producing
``[no key]``, including PostgreSQL constructs ``hstore``
and ``array``.  These have been amended to use inherit
cache where appropriate.  "on conflict" constructs in
PostgreSQL, MySQL, SQLite still explicitly don't generate
a cache key at this time.

The change also adds a test for all constructs via
assert_compile() to assert they will not generate cache
warnings.

Fixes: #7394
Change-Id: I85958affbb99bfad0f5efa21bc8f2a95e7e46981

3 years agoAdd __copy__, __deepcopy__ to URL. Fixes: #7400
Tom Ritchford [Sun, 5 Dec 2021 18:27:45 +0000 (13:27 -0500)] 
Add __copy__, __deepcopy__ to URL. Fixes: #7400

Added support for ``copy()`` and ``deepcopy()`` to the :class:`_url.URL`
class. Pull request courtesy Tom Ritchford.

Fixes: #7400
Closes: #7401
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7401
Pull-request-sha: a2c1b8992f5d153c6210178cda47b8ae96b91fb5

Change-Id: I55977338b2655a7d4f733ae786d31e589185e9ca

3 years agocontextmanager skips rollback if trans says to skip it
Mike Bayer [Thu, 2 Dec 2021 00:27:25 +0000 (19:27 -0500)] 
contextmanager skips rollback if trans says to skip it

Fixed issue where if an exception occurred when the :class:`_orm.Session`
were to close the connection within the :meth:`_orm.Session.commit` method,
when using a context manager for :meth:`_orm.Session.begin` , it would
attempt a rollback which would not be possible as the :class:`_orm.Session`
was in between where the transaction is committed and the connection is
then to be returned to the pool, raising the exception "this
sessiontransaction is in the committed state". This exception can occur
mostly in an asyncio context where CancelledError can be raised.

Fixes: #7388
Change-Id: I1a85a3a7eae79f3553ddf1e3d245a0d90b0a2f40

3 years agoqualify the stringification warning
Mike Bayer [Mon, 6 Dec 2021 17:41:36 +0000 (12:41 -0500)] 
qualify the stringification warning

the recipe which uses render_postcompile itself is
not insecure as it still renders bound parameters
and does not stringify any literal values.

Change-Id: Ib5ac2f7ce37dc1415a67b117a9c31c0ee37270b3

3 years agofix typo in exists documentation
Federico Caselli [Sun, 5 Dec 2021 21:14:09 +0000 (22:14 +0100)] 
fix typo in exists documentation

Change-Id: I44d8d6ee4816052a8dda64c00905b17b7ad8698e

3 years agoMerge "The where method of exists now accepts multiple cluase." into main
mike bayer [Sun, 5 Dec 2021 19:24:12 +0000 (19:24 +0000)] 
Merge "The where method of exists now accepts multiple cluase." into main

3 years agoRemove reference in docs to ThreadLocalMetaData which was removed
Federico Caselli [Sat, 4 Dec 2021 22:14:10 +0000 (23:14 +0100)] 
Remove reference in docs to ThreadLocalMetaData which was removed
in e88dc004e6bcd1418cb8eb811d0aa580c2a44b8f

Change-Id: I1ec3131b35ff62ccc8dc5489238b11d70623cbdc

3 years agoThe where method of exists now accepts multiple cluase.
Federico Caselli [Sat, 4 Dec 2021 22:08:05 +0000 (23:08 +0100)] 
The where method of exists now accepts multiple cluase.

Support multiple clause elements in the :meth:`_sql.Exists.where` method,
unifying the api with the on presented by a normal :func:`_sql.select`
construct.

Fixes: #7386
Change-Id: I5df20478008cd5167053d357cbfad8a641c62b44

3 years agoMerge "Removals: MetaData.bind, Table.bind, all other .bind" into main
mike bayer [Fri, 3 Dec 2021 15:35:13 +0000 (15:35 +0000)] 
Merge "Removals: MetaData.bind, Table.bind, all other .bind" into main

3 years agoMerge "copy list for __iadd__" into main
mike bayer [Fri, 3 Dec 2021 15:34:37 +0000 (15:34 +0000)] 
Merge "copy list for __iadd__" into main

3 years agocopy list for __iadd__
Mike Bayer [Thu, 2 Dec 2021 02:39:59 +0000 (21:39 -0500)] 
copy list for __iadd__

Fixed issue where a list mapped with :func:`_orm.relationship` would go
into an endless loop if in-place added to itself, i.e. the ``+=`` operator
were used, as well as if ``.extend()`` were given the same list.

Fixes: #7389
Change-Id: Idd5118420f8bc684d1ee36b2b6d4c5812f36cc4c

3 years agoMerge "Add __class_getitem__ to the declarative Base class" into main
mike bayer [Thu, 2 Dec 2021 19:51:42 +0000 (19:51 +0000)] 
Merge "Add __class_getitem__ to the declarative Base class" into main

3 years agoRemovals: MetaData.bind, Table.bind, all other .bind
Mike Bayer [Wed, 1 Dec 2021 15:53:16 +0000 (10:53 -0500)] 
Removals: MetaData.bind, Table.bind, all other .bind

Change-Id: I1ef2eb2018f4b68825fe40a2a8d99084cf217b35
References: #7257

3 years agofix typo in documentation
Federico Caselli [Wed, 1 Dec 2021 22:50:13 +0000 (23:50 +0100)] 
fix typo in documentation

Change-Id: I620977b0665d9b3c2cc9ade9db475c357f537ff9

3 years agoAdd __class_getitem__ to the declarative Base class
Kai Mueller [Wed, 1 Dec 2021 15:58:40 +0000 (10:58 -0500)] 
Add __class_getitem__ to the declarative Base class

Fixed issue where the :func:`_orm.as_declarative` decorator and similar
functions used to generate the declarative base class would not copy the
``__class_getitem__()`` method from a given superclass, which prevented the
use of pep-484 generics in conjunction with the ``Base`` class. Pull
request courtesy Kai Mueller.

Fixes: #7368
Closes: #7381
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7381
Pull-request-sha: 7db7fd869a6bb617f767fad5b71ddf7cb5f14ff5

Change-Id: I495718c3082ad6dd2c83fdbf6feba7c529e351cb

3 years agoMerge "Fixes: #4390" into main
mike bayer [Tue, 30 Nov 2021 15:54:29 +0000 (15:54 +0000)] 
Merge "Fixes: #4390" into main

3 years agoMerge "document get_bind() overrides for async session" into main
mike bayer [Tue, 30 Nov 2021 15:48:55 +0000 (15:48 +0000)] 
Merge "document get_bind() overrides for async session" into main

3 years agoscoped_session adjustments
Mike Bayer [Tue, 30 Nov 2021 14:06:29 +0000 (09:06 -0500)] 
scoped_session adjustments

* fix typo, change to a note the async scoped session note
* more dragons re: threading.local()

Change-Id: I76266507510e4014456d992656f4aadf6d03ba4a

3 years agoMerge "adapt pytest plugin to support pytest v7" into main
mike bayer [Mon, 29 Nov 2021 23:07:21 +0000 (23:07 +0000)] 
Merge "adapt pytest plugin to support pytest v7" into main

3 years agodocument get_bind() overrides for async session
Mike Bayer [Mon, 29 Nov 2021 22:00:21 +0000 (17:00 -0500)] 
document get_bind() overrides for async session

Change-Id: Ifcc936a5861d49857d1f365416190cfbd0981aac
References: #7383

3 years agoadapt pytest plugin to support pytest v7
Federico Caselli [Sat, 27 Nov 2021 08:53:29 +0000 (09:53 +0100)] 
adapt pytest plugin to support pytest v7

Implemented support for the test suite to run correctly under Pytest 7.
Previously, only Pytest 6.x was supported for Python 3, however the version
was not pinned on the upper bound in tox.ini. Pytest is not pinned in
tox.ini to be lower than version 8 so that SQLAlchemy versions released
with the current codebase will be able to be tested under tox without
changes to the environment.   Much thanks to the Pytest developers for
their help with this issue.

Change-Id: I3b12166199be2b913ee16e78b3ebbff415654396

3 years agoMerge "provide connectionfairy on initialize" into main
mike bayer [Mon, 29 Nov 2021 20:59:41 +0000 (20:59 +0000)] 
Merge "provide connectionfairy on initialize" into main

3 years agoprovide connectionfairy on initialize
Mike Bayer [Fri, 26 Nov 2021 15:17:38 +0000 (10:17 -0500)] 
provide connectionfairy on initialize

This is so that dialect methods that are called within init
can assume the same argument structure as when they are called
in other places; we can nail down the type of object as well.

This change seems to mostly impact the isolation level routines
in the dialects, as these are called during initialize()
as well as on established connections.  these methods can now
assume a non-proxied DBAPI connection object in all cases,
as it is commonly required that attributes like ".autocommit"
are set on the object which don't work well in a proxied
situation.

Other changes:

* adds an interface for the "connectionfairy" concept
  called PoolProxiedConnection.
* Removes ``Connectable`` superclass of Connection.
  ``Connectable`` was originally meant to provide for the
  "method which accepts connection or engine" theme.  As this
  pattern  is greatly reduced in 2.0 and Engine no longer extends
  from it, the ``Connectable`` superclass doesnt serve any real
  purpose.

Leading from that, to set this in I also applied pep 484 annotations
to the Dialect base, and then in the interests of seeing some
of the typing information show up in my IDE did a little bit for Engine,
Connection and others.  I hope that it's feasible that we can
add annotations to specific classes and attributes ahead of when we
actually try to mass-populate the whole library.  This was
the original spirit of pep-484 that we can apply annotations
gradually.  I do of course want to try to do a mass-populate
although i think even in that case we will end up doing a lot
of manual work anyway (in particular for the changes here which
are distinct from what the stubs have).

Fixes: #7122
Change-Id: I5dd7fbff8a7ae520a81c165091af12a6a68826db

3 years agoupdate migration strategy for dynamic loaders
Mike Bayer [Sat, 27 Nov 2021 19:29:00 +0000 (14:29 -0500)] 
update migration strategy for dynamic loaders

discuss the two current ways for this use case that
use 2.0 style querying and introduce that a newer API
is likely on the way.

Also repair autofunctions for with_parent for 2.0 only.

References: #7123
References: #7372

Change-Id: I2ff6cfd780540ee4ee887b61137af7afa1327a9f

3 years agoFix a typo in psycopg_async module name (#7369)
Denis Laxalde [Sat, 27 Nov 2021 10:09:57 +0000 (11:09 +0100)] 
Fix a typo in psycopg_async module name (#7369)

3 years ago"graceful fetch" test should....clean up gracefully!
Mike Bayer [Fri, 26 Nov 2021 23:43:23 +0000 (18:43 -0500)] 
"graceful fetch" test should....clean up gracefully!

this test was relying on gc to close out the connection.
this would lead to problems with aiosqlite as we invalidate
async connetions that aren't gracefully closed, and this test
suite was create tables per suite, so we'd get into a spot where
a new sqlite memory connection without the tables would get set up.

would only occur for full test run + -n2 + C extensions + python 3.7,
but we assume that is all related to just getting gc to trigger
or not trigger at exactly the right moment in this situation.

confirmed if we add a gc.collect() to the test without explcitly
closing out the conenction, the connection is gc'ed and detached,
and we get the error reproduced on the subsequent test.

Change-Id: Icc9d4bc703f0842c27600f532f34bc4c7d3baf21

3 years agoAdded support for ``psycopg`` dialect.
Federico Caselli [Tue, 14 Sep 2021 21:38:00 +0000 (23:38 +0200)] 
Added support for ``psycopg`` dialect.

Both sync and async versions are supported.

Fixes: #6842
Change-Id: I57751c5028acebfc6f9c43572562405453a2f2a4