Mike Bayer [Sun, 4 Apr 2021 04:41:28 +0000 (00:41 -0400)]
Document inserted_primary_key_rows
This accessor was misleading in that it indicated a general
capability to return inserted primary key values for multiple
rows at once. Clarify this is not currently the case
as the feature is only suppported by the psycopg2 dialect
at the moment.
Mike Bayer [Fri, 2 Apr 2021 15:06:28 +0000 (11:06 -0400)]
Ensure Grouping._with_binary_element_type() maintains class
Fixed regression where use of the :meth:`.Operators.in_` method with a
:class:`_sql.Select` object against a non-table-bound column would produce
an ``AttributeError``, or more generally using a :class:`_sql.ScalarSelect`
that has no datatype in a binary expression would produce invalid state.
Mike Bayer [Thu, 1 Apr 2021 21:20:31 +0000 (17:20 -0400)]
Default caching to opt-out for 3rd party dialects
Added a new flag to the :class:`_engine.Dialect` class called
:attr:`_engine.Dialect.supports_statement_cache`. This flag now needs to be present
directly on a dialect class in order for SQLAlchemy's
:ref:`query cache <sql_caching>` to take effect for that dialect. The
rationale is based on discovered issues such as :ticket:`6173` revealing
that dialects which hardcode literal values from the compiled statement,
often the numerical parameters used for LIMIT / OFFSET, will not be
compatible with caching until these dialects are revised to use the
parameters present in the statement only. For third party dialects where
this flag is not applied, the SQL logging will show the message "dialect
does not support caching", indicating the dialect should seek to apply this
flag once they have verified that no per-statement literal values are being
rendered within the compilation phase.
Federico Caselli [Mon, 29 Mar 2021 20:30:49 +0000 (22:30 +0200)]
Add ``omit_aliases`` in ``Enum``.
Introduce a new parameter :paramref:`_types.Enum.omit_aliases` in
:class:`_types.Enum` type allow filtering aliases when using a pep435 Enum.
Previous versions of SQLAlchemy kept aliases in all cases, creating
database enum type with additional states, meaning that they were treated
as different values in the db. For backward compatibility this flag
defaults to ``False`` in the 1.4 series, but will be switched to ``True``
in a future version. A deprecation warning is raise if this flag is not
specified and the passed enum contains aliases.
Mike Bayer [Thu, 1 Apr 2021 16:46:41 +0000 (12:46 -0400)]
Apply quoting to render_derived() names
Fixed bug in new :meth:`_functions.FunctionElement.render_derived` feature
where column names rendered out explicitly in the alias SQL would not have
proper quoting applied for case sensitive names and other non-alphanumeric
names.
Mike Bayer [Thu, 1 Apr 2021 16:26:06 +0000 (12:26 -0400)]
Correct for Variant + ARRAY cases in psycopg2
Fixed regression caused by :ticket:`6023` where the PostgreSQL cast
operator applied to elements within an :class:`_types.ARRAY` when using
psycopg2 would fail to use the correct type in the case that the datatype
were also embedded within an instance of the :class:`_types.Variant`
adapter.
Additionally, repairs support for the correct CREATE TYPE to be emitted
when using a ``Variant(ARRAY(some_schema_type))``.
Federico Caselli [Tue, 30 Mar 2021 21:15:04 +0000 (23:15 +0200)]
Fix MSSQL / Oracle limit/offset regressions
Fixed a regression in MSSQL 2012+ that prevented the order clause
to be rendered when ``offset=0`` is used in a subquery.
Fixed critical regression where the Oracle compiler would not maintain the
correct parameter values in the LIMIT/OFFSET for a select due to a caching
issue.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #6163 Fixes: #6173
Change-Id: Ieb12354271d09ad935d684ee0db4fa0128837215
Mike Bayer [Wed, 31 Mar 2021 23:38:10 +0000 (19:38 -0400)]
Correct for CTE correspondence w/ aliased CTE
Fixed regression where the :func:`_orm.joinedload` loader strategy would
not successfully joinedload to a mapper that is mapper against a
:class:`.CTE` construct.
Mike Bayer [Sun, 28 Mar 2021 15:09:40 +0000 (11:09 -0400)]
Add DeclarativeMeta to globals
Fixed issue in mypy plugin where newly added support for
:func:`_orm.as_declarative` needed to more fully add the
``DeclarativeMeta`` class to the mypy interpreter's state so that it does
not result in a name not found error; additionally improves how global
names are setup for the plugin including the ``Mapped`` name.
Introduces directory oriented testing as well, where a full
set of files will be copied, mypy runs, then zero or more patches
are applied and mypy is run again, to fully test incremental
behaviors.
Mike Bayer [Wed, 31 Mar 2021 17:16:04 +0000 (13:16 -0400)]
Expand sibling tests for overlaps warning
Scaled back the warning message added in :ticket:`5171` to not warn for
overlapping columns in an inheritance scenario where a particular
relationship is local to a subclass and therefore does not represent an
overlap.
Add errors documentation for the warning and also expand
``util.warn()`` to include a code parameter.
Mike Bayer [Wed, 31 Mar 2021 15:48:22 +0000 (11:48 -0400)]
Repair PGInspector
Fixed issue where the PostgreSQL :class:`.PGInspector`, when generated
against an :class:`_engine.Engine`, would fail for ``.get_enums()``,
``.get_view_names()``, ``.get_foreign_table_names()`` and
``.get_table_oid()`` when used against a "future" style engine and not the
connection directly.
Mike Bayer [Wed, 31 Mar 2021 00:30:13 +0000 (20:30 -0400)]
asyncio API can be considered beta level
It's clear that there are at least many dozens of developers
working with the new asyncio extension and we have not had
any major bug reports. Other than ``Session.delete`` needing
to be an awaitable, there were no backwards-incompatible issues
and we've seen no issues with wrong behaviors.
hbusul [Mon, 29 Mar 2021 15:42:33 +0000 (11:42 -0400)]
accommodate new pg8000 disconnection exception
Modified the ``is_disconnect()`` handler for the pg8000 dialect, which now
accommodates for a new ``InterfaceError`` emitted by pg8000 1.19.0. Pull
request courtesy Hamdi Burak Usul.
Mike Bayer [Mon, 29 Mar 2021 21:57:20 +0000 (17:57 -0400)]
TypeDecorator passes "outer" flag to itself for set_parent accounting
Fixed bug first introduced in as some combination of :ticket:`2892`,
:ticket:`2919` nnd :ticket:`3832` where the attachment events for a
:class:`_types.TypeDecorator` would be doubled up against the "impl" class,
if the "impl" were also a :class:`_types.SchemaType`. The real-world case
is any :class:`_types.TypeDecorator` against :class:`_types.Enum` or
:class:`_types.Boolean` would get a doubled
:class:`_schema.CheckConstraint` when the ``create_constraint=True`` flag
is set.
Mike Bayer [Mon, 29 Mar 2021 20:40:16 +0000 (16:40 -0400)]
Run trans.close() at end of block if transaction already inactive
Modified the context manager used by :class:`_engine.Transaction` so that
an "already detached" warning is not emitted by the ending of the context
manager itself, if the transaction were already manually rolled back inside
the block. This applies to regular transactions, savepoint transactions,
and legacy "marker" transactions. A warning is still emitted if the
``.rollback()`` method is called explicitly more than once.
Mike Bayer [Tue, 30 Mar 2021 02:38:09 +0000 (22:38 -0400)]
Adapt for importlib_metadata changes
importlib_metadata deprecates the .get() method and provides
a different method .select() as of 3.7.1. Work around
the deprecation warning in this case.
Mike Bayer [Sat, 27 Mar 2021 12:36:32 +0000 (08:36 -0400)]
Commentary; run criteria.params() if statement isn't cached?
Considering adjustment to 56f9c7743e9083add69a10501a503f,
if statement is not cached, skip the relatively expensive
step of re-processing the criteria clause.
However, this causes the overall cache key of the statement
to come out differently which should also be avoided.
Likely we would not merge the actual change, just the
comment here.
Mike Bayer [Fri, 26 Mar 2021 19:40:34 +0000 (15:40 -0400)]
run new relationship criteria tests on empty session
The commit in 56f9c7743e9083add69a10501a503f4 forgot to make
sure the full reload took place, either via populate_existing()
or session.close(), with failure only showing up in pypy.
Mike Bayer [Fri, 26 Mar 2021 14:37:21 +0000 (10:37 -0400)]
Adapt loader_criteria params for current query
Fixed critical issue in the new :meth:`_orm.PropComparator.and_` feature
where loader strategies that emit secondary SELECT statements such as
:func:`_orm.selectinload` and :func:`_orm.lazyload` would fail to
accommodate for bound parameters in the user-defined criteria in terms of
the current statement being executed, as opposed to the cached statement,
causing stale bound values to be used.
This also adds a warning for the case where an object that uses
:func:`_orm.lazyload` in conjunction with :meth:`_orm.PropComparator.and_`
is attempted to be serialized; the loader criteria cannot reliably
be serialized and deserialized and eager loading should be used for this
case.
Mike Bayer [Tue, 23 Mar 2021 22:49:28 +0000 (18:49 -0400)]
support as_declarative, as_declarative_base
Added support for the Mypy extension to correctly interpret a declarative
base class that's generated using the :func:`_orm.as_declarative` function
as well as the :meth:`_orm.registry.as_declarative_base` method.
Mike Bayer [Thu, 25 Mar 2021 14:37:12 +0000 (10:37 -0400)]
don't rely on pk-only group_by
Fixed the test test_aliased_stmt_includes_unnamed_fn
recently added in c1c999c01d to include the additional
column in the GROUP BY statement, allowing this statement
to succeed on SQL Server which seems to not support "group by pk only"
syntax.
Mike Bayer [Thu, 25 Mar 2021 12:40:16 +0000 (08:40 -0400)]
Accept **kw in annotated._clone() method
Fixed bug where combinations of the new "relationship with criteria"
feature could fail in conjunction with features that make use of the new
"lambda SQL" feature, including loader strategies such as selectinload and
lazyload, for more complicated scenarios such as polymorphic loading.
Mike Bayer [Wed, 24 Mar 2021 21:43:06 +0000 (17:43 -0400)]
Use class-local metadata for declarative base
Fixed regression where the ``.metadata`` attribute on a per class level
would not be honored, breaking the use case of per-class-hierarchy
:class:`.schema.MetaData` for abstract declarative classes and mixins.
Mike Bayer [Wed, 24 Mar 2021 15:33:04 +0000 (11:33 -0400)]
Repair pysqlcipher and use sqlcipher3
The ``pysqlcipher`` dialect now imports the ``sqlcipher3`` module
for Python 3 by default. Regressions have been repaired such that
the connection routine was not working.
To better support the post-connection steps of the pysqlcipher
dialect, a new hook Dialect.on_connect_url() is added, which
supersedes Dialect.on_connect() and is passed the URL object.
The dialect now pulls the passphrase and other cipher args
from the URL directly without including them in the
"connect" args. This will allow any user-defined extensibility
to connecting to work as it would for other dialects.
The commit also builds upon the extended routines in
sqlite/provisioning.py to better support running tests against
multiple simultaneous SQLite database files. Additionally enables
backend for test_sqlite which was skipping everything
for aiosqlite too, fortunately everything there is passing.
Mike Bayer [Wed, 24 Mar 2021 16:15:53 +0000 (12:15 -0400)]
Support __visit_name__ on PropComparator to work in cloning
Repaired support so that the :meth:`_sql.Select.params` method can work
correctly with a :class:`_sql.Select` object that includes joins across ORM
relationship structures, which is a new feature in 1.4.
Martin Häcker [Tue, 23 Mar 2021 15:46:18 +0000 (11:46 -0400)]
Use compat.exec_()
Fixed a bug where python 2.7.5 (default on CentOS 7) wasn't able to import
sqlalchemy, because on this version of Python ``exec "statement"`` and
``exec("statement")`` do not behave the same way. The compatibility
``exec_()`` function was used instead.
Mike Bayer [Tue, 23 Mar 2021 02:56:36 +0000 (22:56 -0400)]
Remove internal use of string attr in loader option
Fixed issue where a "removed in 2.0" warning were generated internally by
the relationship loader mechanics.
This changeset started the effort of converting all string usage
in the test suite, however this is a much longer job as the
use of strings in loader options is widespread. In particular
I'm not totally comfortable with strings not being accepted
in obvious spots like Load(User).load_only("x", "y", "z"), which
points to a new string expecting functionality that's not
what's there now. However at the moment it seems like we need
to continue removing all support for strings and then figure out
"immediate strings from an explicit class" later.
Mike Bayer [Tue, 16 Mar 2021 23:46:40 +0000 (19:46 -0400)]
Adjust derivation rules for table vs. subquery against a join
Fixed bug where ORM queries using a correlated subquery in conjunction with
:func:`_orm.column_property` would fail to correlate correctly to an
enclosing subquery or to a CTE when :meth:`_sql.Select.correlate_except`
were used in the property to control correlation, in cases where the
subquery contained the same selectables as ones within the correlated
subquery that were intended to not be correlated.
This is achieved by adding a limiting factor to ClauseAdapter
which is to explicitly pass the selectables we will be adapting
"from", which is then used by AliasedClass to limit "from"
to the mappers represented by the AliasedClass.
This did cause one test where an alias for a contains_eager()
was missing to suddenly fail, and the test was corrected, however
there may be some very edge cases like that one where the tighter
criteria causes an existing use case that's relying on the more
liberal aliasing to require modifications.
Mike Bayer [Tue, 23 Mar 2021 14:23:23 +0000 (10:23 -0400)]
warn / document for Query.with_polymorphic() with with_loader_criteria()
These are illustrated as not working in #6111. As this is
a highly complex and legacy method, encourage users to
migrate off of it before using with_loader_criteria().
Mike Bayer [Sun, 21 Mar 2021 21:10:18 +0000 (17:10 -0400)]
Add support for Boolean, Enum
Fixed bug in Mypy plugin where the Python type detection
for the :class:`_sqltypes.Boolean` column type would produce
an exception; additionally implemented support for :class:`_sqltypes.Enum`,
including detection of a string-based enum vs. use of Python ``enum.Enum``.