Mike Bayer [Thu, 11 Apr 2019 18:21:13 +0000 (14:21 -0400)]
Remove threadlocal engine strategy, engine strategies pool threadlocal
The "threadlocal" execution strategy, deprecated in 1.3, has been
removed for 1.4, as well as the concept of "engine strategies" and the
``Engine.contextual_connect`` method. The "strategy='mock'" keyword
argument is still accepted for now with a deprecation warning; use
:func:`.create_mock_engine` instead for this use case.
Mike Bayer [Sun, 14 Jul 2019 15:43:29 +0000 (11:43 -0400)]
Add profile sort option to test suite
I use the nfl sort a lot to see what calling changes are happening
between two versions in order to identify the offending code, so
add it as a command line option.
Mike Bayer [Sat, 13 Jul 2019 02:43:31 +0000 (22:43 -0400)]
self_group() for FunctionFilter
Fixed issue where the :class:`.array_agg` construct in combination with
:meth:`.FunctionElement.filter` would not produce the correct operator
precedence between the FILTER keyword and the array index operator.
Mike Bayer [Sun, 7 Jul 2019 15:12:31 +0000 (11:12 -0400)]
Allow duplicate columns in from clauses and selectables
The :func:`.select` construct and related constructs now allow for
duplication of column labels and columns themselves in the columns clause,
mirroring exactly how column expressions were passed in. This allows
the tuples returned by an executed result to match what was SELECTed
for in the first place, which is how the ORM :class:`.Query` works, so
this establishes better cross-compatibility between the two constructs.
Additionally, it allows column-positioning-sensitive structures such as
UNIONs (i.e. :class:`.CompoundSelect`) to be more intuitively constructed
in those cases where a particular column might appear in more than one
place. To support this change, the :class:`.ColumnCollection` has been
revised to support duplicate columns as well as to allow integer index
access.
Mike Bayer [Thu, 11 Jul 2019 15:56:54 +0000 (11:56 -0400)]
profiling plugin fixes
support that we have pytest-xdist arguments now,
as well as allow force-write to reset the list of callcounts which
seem to accumulate commas for some reason
Mike Bayer [Wed, 10 Jul 2019 20:12:48 +0000 (16:12 -0400)]
Add performance improvement for Enum w/ Python 2 enum library
Adjusted the initialization for :class:`.Enum` to minimize how often it
invokes the ``.__members__`` attribute of a given PEP-435 enumeration
object, to suit the case where this attribute is expensive to invoke, as is
the case for some popular third party enumeration libraries.
Mike Bayer [Mon, 8 Jul 2019 19:46:35 +0000 (15:46 -0400)]
Support multidimensional array literals in Postgresql
Added support for multidimensional Postgresql array literals via nesting
the :class:`.postgresql.array` object within another one. The
multidimensional array type is detected automatically.
Mike Bayer [Mon, 8 Jul 2019 14:42:20 +0000 (10:42 -0400)]
Ensure .engine is part of Connectable interface, implement as descriptor
Fixed bug where using reflection function such as :meth:`.MetaData.reflect`
with an :class:`.Engine` object that had execution options applied to it
would fail, as the resulting :class:`.OptionEngine` proxy object failed to
include a ``.engine`` attribute used within the reflection routines.
Mike Bayer [Thu, 13 Jun 2019 16:37:22 +0000 (12:37 -0400)]
SelectBase no longer a FromClause
As part of the SQLAlchemy 2.0 migration project, a conceptual change has
been made to the role of the :class:`.SelectBase` class hierarchy,
which is the root of all "SELECT" statement constructs, in that they no
longer serve directly as FROM clauses, that is, they no longer subclass
:class:`.FromClause`. For end users, the change mostly means that any
placement of a :func:`.select` construct in the FROM clause of another
:func:`.select` requires first that it be wrapped in a subquery first,
which historically is through the use of the :meth:`.SelectBase.alias`
method, and is now also available through the use of
:meth:`.SelectBase.subquery`. This was usually a requirement in any
case since several databases don't accept unnamed SELECT subqueries
in their FROM clause in any case.
See the documentation in this change for lots more detail.
Mike Bayer [Fri, 5 Jul 2019 16:19:55 +0000 (12:19 -0400)]
Note DBAPIs and dialects that we don't support
Since we have strong CI for the DBAPIs and dialects that are actively
supported, this indicates that those DBAPIs that aren't in CI are
continuing to fall behind in support, to the point where we can
not address issues that may arise. As such, the Sybase and Firebird
dialects overall are moving into an explicit "not supported" zone
where we would like to eventually remove them. Additionally,
a pass is made through legacy MySQL and PostgreSQL DBAPI dialects
as well as those which we aren't able to include in CI to note
that these DBAPIs aren't actively supported by the project.
Mike Bayer [Tue, 2 Jul 2019 02:33:26 +0000 (22:33 -0400)]
Clear proxy_set cache when creating an annotated column
Fixed an unlikely issue where the "corresponding column" routine for unions
and other :class:`.CompoundSelect` objects could return the wrong column in
some overlapping column situtations, thus potentially impacting some ORM
operations when set operations are in use, if the underlying
:func:`.select` constructs were used previously in other similar kinds of
routines, due to a cached value not being cleared.
Denis Kataev [Fri, 28 Jun 2019 13:57:47 +0000 (09:57 -0400)]
Test for _ORMJoin and fix issue
Fixed an issue where the :meth:`.orm._ORMJoin.join` method, which is a
not-internally-used ORM-level method that exposes what is normally an
internal process of :meth:`.Query.join`, did not propagate the ``full`` and
``outerjoin`` keyword arguments correctly. Pull request courtesy Denis
Kataev.
Mike Bayer [Fri, 28 Jun 2019 14:41:38 +0000 (10:41 -0400)]
CAST bind values against SQL Server sys into NVARCHAR
Ensured that the queries used to reflect indexes and view definitions will
explicitly CAST string parameters into NVARCHAR, as many SQL Server drivers
frequently treat string values, particularly those with non-ascii
characters or larger string values, as TEXT which often don't compare
correctly against VARCHAR characters in SQL Server's information schema
tables for some reason. These CAST operations already take place for
reflection queries against SQL Server ``information_schema.`` tables but
were missing from three additional queries that are against ``sys.``
tables.
Mike Bayer [Thu, 20 Jun 2019 19:37:59 +0000 (15:37 -0400)]
Add Load.options() for hierchical construction of loader options
Added new loader option method :meth:`.Load.options` which allows loader
options to be constructed hierarchically, so that many sub-options can be
applied to a particular path without needing to call :func:`.defaultload`
many times. Thanks to Alessio Bogon for the idea.
Also applies a large pass to the loader option documentation which
needed improvement.
Unfortunately target version py27 makes Black want to break
print functions, even if you put a "from __future__ import print_function"
at the top, so it is being inconsistent in its "we've decided this
is a python 2 file" logic and basically this thing really needs
command line arguments
Mike Bayer [Thu, 27 Jun 2019 17:25:12 +0000 (13:25 -0400)]
Unwrap TIMESTAMP when doing an isinstance()
Fixed bug where the special logic to render "NULL" for the
:class:`.TIMESTAMP` datatype when ``nullable=True`` would not work if the
column's datatype were a :class:`.TypeDecorator` or a :class:`.Variant`.
The logic now ensures that it unwraps down to the original
:class:`.TIMESTAMP` so that this special case NULL keyword is correctly
rendered when requested.
Mike Bayer [Thu, 27 Jun 2019 14:07:04 +0000 (10:07 -0400)]
Remove test-within-a-test structure
These tests in of_type were relying upon generating the
polymorphic selectable from the mapper which is proving to be
more challenging to correct when that mechanism is changing.
Mike Bayer [Wed, 26 Jun 2019 15:45:50 +0000 (11:45 -0400)]
Reflect "NO ACTION" as None; support "RESTRICT"
The "NO ACTION" keyword for foreign key "ON UPDATE" is now considered to be
the default cascade for a foreign key on all supporting backends (SQlite,
MySQL, PostgreSQL) and when detected is not included in the reflection
dictionary; this is already the behavior for PostgreSQL and MySQL for all
previous SQLAlchemy versions in any case. The "RESTRICT" keyword is
positively stored when detected; PostgreSQL does report on this keyword,
and MySQL as of version 8.0 does as well. On earlier MySQL versions, it is
not reported by the database.
Mike Bayer [Fri, 21 Jun 2019 19:23:52 +0000 (15:23 -0400)]
Register pytest assertion rewriting on sqlalchemy.testing.assertions
Since our various eq_(), ne_() etc. functions use assert, pytest
can rewrite this module using its enhanced string reporting.
very helpful for comparing SQL strings
Mike Bayer [Thu, 20 Jun 2019 21:18:59 +0000 (17:18 -0400)]
Add option for "sparse" backend tests and apply to memusage
The memusage tests are extremely time and memory intensive,
and when CI runs against MySQL or Postgresql there are many
database/driver combinations for which the "backend" tests
repeatedly run; as these tests are more oriented towards
basic dialect interaction, add a new "sparse" backend option
that will run the tests only once per base dialect.
Mike Bayer [Thu, 30 May 2019 15:31:03 +0000 (11:31 -0400)]
Enable F841
This is a very useful assertion which prevents unused variables
from being set up allows code to be more readable and sometimes
even more efficient. test suites seem to be where the most
problems are and there do not seem to be documentation examples
that are using this, or at least the linter is not taking effect
within rst blocks.
Eli Collins [Thu, 13 Jun 2019 14:37:16 +0000 (10:37 -0400)]
PostgreSQL now reflects per-column sort order on indexes.
Added support for column sorting flags when reflecting indexes for
PostgreSQL, including ASC, DESC, NULLSFIRST, NULLSLAST. Also adds this
facility to the reflection system in general which can be applied to other
dialects in future releases. Pull request courtesy Eli Collins.
Mike Bayer [Sat, 15 Jun 2019 22:06:50 +0000 (18:06 -0400)]
Turn off the is_literal flag when proxying literal_column() to Label
Fixed a series of quoting issues which all stemmed from the concept of the
:func:`.literal_column` construct, which when being "proxied" through a
subquery to be referred towards by a label that matches its text, the label
would not have quoting rules applied to it, even if the string in the
:class:`.Label` were set up as a :class:`.quoted_name` construct. Not
applying quoting to the text of the :class:`.Label` is a bug because this
text is strictly a SQL identifier name and not a SQL expression, and the
string should not have quotes embedded into it already unlike the
:func:`.literal_column` which it may be applied towards. The existing
behavior of a non-labeled :func:`.literal_column` being propagated as is on
the outside of a subquery is maintained in order to help with manual
quoting schemes, although it's not clear if valid SQL can be generated for
such a construct in any case.
Mike Bayer [Sat, 15 Jun 2019 02:44:59 +0000 (22:44 -0400)]
Consult is_attrbute flag to determine descriptor; enable for assoc proxy
Fixed bug where the :attr:`.Mapper.all_orm_descriptors` accessor would
return an entry for the :class:`.Mapper` itself under the declarative
``__mapper___`` key, when this is not a descriptor. The ``.is_attribute``
flag that's present on all :class:`.InspectionAttr` objects is now
consulted, which has also been modified to be ``True`` for an association
proxy, as it was erroneously set to False for this object.
Mike Bayer [Thu, 13 Jun 2019 20:35:12 +0000 (16:35 -0400)]
Generate Oracle ROWNUM scheme using named subqueries
The LIMIT / OFFSET scheme used in Oracle now makes use of named subqueries
rather than unnamed subqueries when it transparently rewrites a SELECT
statement to one that uses a subquery that includes ROWNUM. The change is
part of a larger change where unnamed subqueries are no longer directly
supported by Core, as well as to modernize the internal use of the select()
construct within the Oracle dialect.
Mike Bayer [Thu, 13 Jun 2019 16:45:05 +0000 (12:45 -0400)]
Reverse Alias nesting concept
The Alias object no longer has "element" and "original", it now
has "wrapped" and "element" (the name .original is also left
as a descriptor for legacy access by third party dialects).
These two data members refer to the
dual roles Alias needs to play, where in the Python sense it needs
to refer to the thing it was applied against directly, whereas in the
SQL sense it needs to refer to the ultimate "non-alias" thing it
refers towards. Both are necessary to maintain. However, the change
here has each Alias object access the non-Alias object immediately
so that the "unwrapping" is simpler and does not need any special
logic.
In the SQL sense, Alias objects don't nest, the only potential
was that of the CTE, however there is no such thing as
a nested CTE, see link below.
This change is an interim change along the way to breaking Alias
into more classes and breaking away Select objects from being
FromClause objects.
Mike Bayer [Wed, 12 Jun 2019 17:15:59 +0000 (13:15 -0400)]
Run PK/FK sync for multi-level inheritance w/ no intermediary update
Also fix DetectKeySwitch for intermediary class relationship
Fixed a series of related bugs regarding joined table inheritance more than
two levels deep, in conjunction with modification to primary key values,
where those primary key columns are also linked together in a foreign key
relationship as is typical for joined table inheritance. The intermediary
table in a three-level inheritance hierachy will now get its UPDATE if
only the primary key value has changed and passive_updates=False (e.g.
foreign key constraints not being enforced), whereas before it would be
skipped; similarly, with passive_updates=True (e.g. ON UPDATE CASCADE in
effect), the third-level table will not receive an UPDATE statement as was
the case earlier which would fail since CASCADE already modified it. In a
related issue, a relationship linked to a three-level inheritance hierarchy
on the primary key of an intermediary table of a joined-inheritance
hierarchy will also correctly have its foreign key column updated when the
parent object's primary key is modified, even if that parent object is a
subclass of the linked parent class, whereas before these classes would
not be counted.
Mike Bayer [Fri, 7 Jun 2019 15:19:23 +0000 (11:19 -0400)]
Don't discard inactive transaction until it is explicitly rolled back
The :class:`.Connection` object will now not clear a rolled-back
transaction until the outermost transaction is explicitly rolled back.
This is essentially the same behavior that the ORM :class:`.Session` has
had for a long time, where an explicit call to ``.rollback()`` on all
enclosing transactions is required for the transaction to logically clear,
even though the DBAPI-level transaction has already been rolled back.
The new behavior helps with situations such as the "ORM rollback test suite"
pattern where the test suite rolls the transaction back within the ORM
scope, but the test harness which seeks to control the scope of the
transaction externally does not expect a new transaction to start
implicitly.
Mike Bayer [Sun, 9 Jun 2019 14:59:23 +0000 (10:59 -0400)]
psycopg2 NOTICE fixup
- don't call relatively expensive isEnabledFor(), just call _log_notices
- don't reset the list if it's empty
- fix the test to use a custom function to definitely create a notice, confirmed
that PG seems to no longer create the "implicit sequence" notices
- assert that the reset of the notices works too
- update the docs to illustrate for folks who haven't worked with logging before
Mike Bayer [Fri, 7 Jun 2019 20:04:22 +0000 (16:04 -0400)]
Add "full" to the getargspec warning skip
Even though getfullargspec() is no longer deprecated in python3.8
as of b1, we aren't using it anymore so block any future warnings
from interfering with py.test or similar.
Mike Bayer [Fri, 7 Jun 2019 18:50:22 +0000 (14:50 -0400)]
Rework Session transaction FAQs
In preparation for #4712, add an errors.rst code to the Session's
exception about waiting to be rolled back and rework the FAQ entry
to be much more succinct. When this FAQ was first written, I found
it hard to describe why flush worked this way but as the use case is
clearer now, and #4712 actually showed it being confusing when it doesn't
work this way, we can make a simpler and more definitive statement
about this behavior. Additionally, language about "subtransactions"
is minimized as I might be removing or de-emphasizing this concept in
2.0 (though maybe not as it does seem to work well).
Mike Bayer [Mon, 3 Jun 2019 16:48:14 +0000 (12:48 -0400)]
Add "usecase" changelog tag
"usecase" indicates the library now supports something a user
was trying to do. It's not quite a "feature" since it's something
that seems like it should have worked, it's not a "bug" because
no mistake was made, it's just something that wasn't considered before.
The advantage of "usecase" is that it inherently suggests a different
style of prioritization vs. something that is preventing the library
from working as designed.
This change also adds docs/build/conf.py under the pep8 formatting
test coverage.
Mike Bayer [Fri, 31 May 2019 20:47:19 +0000 (16:47 -0400)]
Apply adaptation for most recent aliased=True first
Fixed regression in :meth:`.Query.join` where the ``aliased=True`` flag
would not properly apply clause adaptation to filter criteria, if a
previous join were made to the same entity. This is because the adapters
were placed in the wrong order. The order has been reversed so that the
adapter for the most recent ``aliased=True`` call takes precedence as was
the case in 1.2 and earlier. This broke the "elementtree" examples among
other things.
Mike Bayer [Fri, 31 May 2019 00:42:35 +0000 (20:42 -0400)]
PostgreSQL enum with no elements returns NULL for the "label", skip this
Fixed bug where PostgreSQL dialect could not correctly reflect an ENUM
datatype that has no members, returning a list with ``None`` for the
``get_enums()`` call and raising a TypeError when reflecting a column which
has such a datatype. The inspection now returns an empty list.
Mike Bayer [Wed, 29 May 2019 21:27:19 +0000 (17:27 -0400)]
Use fully vendored getfullargspec
Replaced the Python compatbility routines for ``getfullargspec()`` with a
fully vendored version from Python 3.3. Originally, Python was emitting
deprecation warnings for this function in Python 3.8 alphas. While this
change was reverted, it was observed that Python 3 implementations for
``getfullargspec()`` are an order of magnitude slower as of the 3.4 series
where it was rewritten against ``Signature``. While Python plans to
improve upon this situation, SQLAlchemy projects for now are using a simple
replacement to avoid any future issues.
Dmytro Starosud [Wed, 29 May 2019 13:47:13 +0000 (16:47 +0300)]
Rework AliasedClass __getattr__ to use top-level getattr()
Reworked the attribute mechanics used by :class:`.AliasedClass` to no
longer rely upon calling ``__getattribute__`` on the MRO of the wrapped
class, and to instead resolve the attribute normally on the wrapped class
using getattr(), and then unwrap/adapt that. This allows a greater range
of attribute styles on the mapped class including special ``__getattr__()``
schemes; but it also makes the code simpler and more resilient in general.
Fixes: #4694 Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I28901e2472d3c21e881fe5cafa3b1d3af704fad8
Mike Bayer [Tue, 28 May 2019 13:46:20 +0000 (09:46 -0400)]
Reformat license name
While we have the OSI classifier for "MIT License", it looks
like for the "license" field, this is normally just the word
"MIT" and not "MIT License". While the pypa docs suggest we
only need it as the OSI classifier, keep it also in "license"
in order to appease common tooling.
Mike Bayer [Sun, 19 May 2019 00:35:01 +0000 (20:35 -0400)]
Use roles for ORM alias() conversion
as SELECT statements will have subquery() and not alias(),
start getting ready for the places where the ORM coerces SELECTs
into subqueries and be ready to warn about it
Mike Bayer [Tue, 28 May 2019 01:15:47 +0000 (21:15 -0400)]
Adjust test_concurrency failure modes
The test added for #4686 can raise for "B" missing which
is normal and should not fail the test. Also ensure mappers are
cleared to prevent subsequent tests elsewhere from being
affected.
Hannes Hansen [Thu, 23 May 2019 20:27:21 +0000 (16:27 -0400)]
MYSQL: added support for drop check/constraint
Added support for DROP CHECK constraint which is required by MySQL 8.0.16
to drop a CHECK constraint; MariaDB supports plain DROP CONSTRAINT. The
logic distinguishes between the two syntaxes by checking the server version
string for MariaDB presence. Alembic migrations has already worked
around this issue by implementing its own DROP for MySQL / MariaDB CHECK
constraints, however this change implements it straight in Core so that its
available for general use. Pull request courtesy Hannes Hansen.
Mike Bayer [Sat, 25 May 2019 22:04:58 +0000 (18:04 -0400)]
Hold implicitly created collections in a pending area
Accessing a collection-oriented attribute on a newly created object no
longer mutates ``__dict__``, but still returns an empty collection as has
always been the case. This allows collection-oriented attributes to work
consistently in comparison to scalar attributes which return ``None``, but
also don't mutate ``__dict__``. In order to accommodate for the collection
being mutated, the same empty collection is returned each time once
initially created, and when it is mutated (e.g. an item appended, added,
etc.) it is then moved into ``__dict__``. This removes the last of
mutating side-effects on read-only attribute access within the ORM.
Mike Bayer [Thu, 23 May 2019 22:01:07 +0000 (18:01 -0400)]
Unify NO_VALUE and NEVER_SET
There's no real difference between these two constants
except they are used in different places and therefore allow
various codepaths to work largely by accident. These
codepaths should be explicit. Assign NO_VALUE and NEVER_SET
to the same constant and work towards having just one constant
for "we have no value to return right now".
Mike Bayer [Thu, 23 May 2019 15:35:51 +0000 (11:35 -0400)]
Include active_history when propagating attribute listeners
Fixed issue where the :paramref:`.AttributeEvents.active_history` flag
would not be set for an event listener that propgated to a subclass via the
:paramref:`.AttributeEvents.propagate` flag. This bug has been present
for the full span of the :class:`.AttributeEvents` system.
Mike Bayer [Sun, 19 May 2019 16:38:14 +0000 (12:38 -0400)]
Add QueryableAttribute._impl_uses_objects accessor for AssociationProxy
Fixed regression where new association proxy system was still not proxying
hybrid attributes when they made use of the ``@hybrid_property.expression``
decorator to return an alternate SQL expression, or when the hybrid
returned an arbitrary :class:`.PropComparator`, at the expression level.
This involved futher generalization of the heuristics used to detect the
type of object being proxied at the level of :class:`.QueryableAttribute`,
to better detect if the descriptor ultimately serves mapped classes or
column expressions.
Mike Bayer [Tue, 30 Apr 2019 03:26:36 +0000 (23:26 -0400)]
Implement new ClauseElement role and coercion system
A major refactoring of all the functions handle all detection of
Core argument types as well as perform coercions into a new class hierarchy
based on "roles", each of which identify a syntactical location within a
SQL statement. In contrast to the ClauseElement hierarchy that identifies
"what" each object is syntactically, the SQLRole hierarchy identifies
the "where does it go" of each object syntactically. From this we define
a consistent type checking and coercion system that establishes well
defined behviors.
This is a breakout of the patch that is reorganizing select()
constructs to no longer be in the FromClause hierarchy.
Also includes a rename of as_scalar() into scalar_subquery(); deprecates
automatic coercion to scalar_subquery().