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().
Mike Bayer [Thu, 16 May 2019 15:26:04 +0000 (11:26 -0400)]
Mutex the declarative scan/map process against configure_mappers()
Applied the mapper "configure mutex" against the declarative class mapping
process, to guard against the race which can occur if mappers are used
while dynamic module import schemes are still in the process of configuring
mappers for related classes. This does not guard against all possible race
conditions, such as if the concurrent import has not yet encountered the
dependent classes as of yet, however it guards against as much as possible
within the SQLAlchemy declarative process.
Mike Bayer [Mon, 13 May 2019 18:56:12 +0000 (14:56 -0400)]
Continue to assume None for un-accessed attribute on persistent
object during m2o fetch
Fixed regression in new relationship m2o comparison logic first introduced
at :ref:`change_4359` when comparing to an attribute that is persisted as
NULL and is in an un-fetched state in the mapped instance. Since the
attribute has no explicit default, it needs to default to NULL when
accessed in a persistent setting.
Mike Bayer [Sat, 11 May 2019 02:36:40 +0000 (22:36 -0400)]
Correct fix and tests for #4661
For #4661 we need to still warn if we are only deleting one row,
even if sane multi rowcount is false. Tests were failing for
pyodbc since the warning was removed for the single-row case.
the UPDATE logic raises if a single row doesn't match even
if sane multi rowcount is false, so this is now more consistent
with that. Add tests for the UPDATE case also. It is possible
there are already tests for this but as the DELETE case wasn't
well covered it's not clear.
Matthew Wilkes [Thu, 9 May 2019 22:04:35 +0000 (18:04 -0400)]
Move initialize do_rollback() outside of the dialect
Moved the "rollback" which occurs during dialect initialization so that it
occurs after additional dialect-specific initialize steps, in particular
those of the psycopg2 dialect which would inadvertently leave transactional
state on the first new connection, which could interfere with some
psycopg2-specific APIs which require that no transaction is started. Pull
request courtesy Matthew Wilkes.
Mike Bayer [Tue, 7 May 2019 15:38:48 +0000 (11:38 -0400)]
Turn FlushError for identity already exists into a warning.
The condition where a pending object being flushed with an identity that
already exists in the identity map has been adjusted to emit a warning,
rather than throw a :class:`.FlushError`. The rationale is so that the
flush will proceed and raise a :class:`.IntegrityError` instead, in the
same way as if the existing object were not present in the identity map
already. This helps with schemes that are uinsg the
:class:`.IntegrityError` as a means of catching whether or not a row
already exists in the table.
mollardthomas [Fri, 3 May 2019 15:31:57 +0000 (11:31 -0400)]
Add support for filtered indexes for mssql dialect
Added support for SQL Server filtered indexes, via the ``mssql_where``
parameter which works similarly to that of the ``postgresql_where`` index
function in the PostgreSQL dialect.
Adrien Berchet [Fri, 3 May 2019 16:02:17 +0000 (12:02 -0400)]
Do not register the GenericFunction in sql.functions._registry
Fixed that the :class:`.GenericFunction` class was inadvertently
registering itself as one of the named functions. Pull request courtesy
Adrien Berchet.
Mike Bayer [Fri, 3 May 2019 22:07:06 +0000 (18:07 -0400)]
Don't warn on multi delete rowcount if supports_sane_multi is False
Fixed an issue where the "number of rows matched" warning would emit even if
the dialect reported "supports_sane_multi_rowcount=False", as is the case
for psycogp2 with ``use_batch_mode=True`` and others.
Mike Bayer [Mon, 29 Apr 2019 21:31:12 +0000 (17:31 -0400)]
Make the GenericFunction registry fully case insensitive
Registered function names based on :class:`.GenericFunction` are now
retrieved in a case-insensitive fashion in all cases, removing the
deprecation logic from 1.3 which temporarily allowed multiple
:class:`.GenericFunction` objects to exist with differing cases. A
:class:`.GenericFunction` that replaces another on the same name whether or
not it's case sensitive emits a warning before replacing the object.
Add case insensitivity feature to GenericFunction.
The :class:`.GenericFunction` namespace is being migrated so that function
names are looked up in a case-insensitive manner, as SQL functions do not
collide on case sensitive differences nor is this something which would
occur with user-defined functions or stored procedures. Lookups for
functions declared with :class:`.GenericFunction` now use a case
insensitive scheme, however a deprecation case is supported which allows
two or more :class:`.GenericFunction` objects with the same name of
different cases to exist, which will cause case sensitive lookups to occur
for that particular name, while emitting a warning at function registration
time. Thanks to Adrien Berchet for a lot of work on this complicated
feature.
Mike Bayer [Wed, 17 Apr 2019 17:37:39 +0000 (13:37 -0400)]
Reimplement .compare() in terms of a visitor
Reworked the :meth:`.ClauseElement.compare` methods in terms of a new
visitor-based approach, and additionally added test coverage ensuring that
all :class:`.ClauseElement` subclasses can be accurately compared
against each other in terms of structure. Structural comparison
capability is used to a small degree within the ORM currently, however
it also may form the basis for new caching features.
Mike Bayer [Sun, 28 Apr 2019 16:40:31 +0000 (12:40 -0400)]
Warn on merge of already-pending object
A warning is now emitted for the case where a transient object is being
merged into the session with :meth:`.Session.merge` when that object is
already transient in the :class:`.Session`. This warns for the case where
the object would normally be double-inserted.
Mike Bayer [Thu, 25 Apr 2019 15:46:31 +0000 (10:46 -0500)]
Add ORM documentation for as_comparison()
In #3831 we added the ability for SQL functions to be used in
primaryjoin conditions as the source of comparison, however we
didn't add documentation from the main relationship docs so
nobody could find it unless they read the migration notes.
Since the two use cases that have come up for this are
materialized path with string functions, and geometry functions,
add the example based on the use case requested in
https://github.com/geoalchemy/geoalchemy2/issues/220#issuecomment-486709055
This example hasn't been tested yet and is subject to
revision.
Mike Bayer [Tue, 23 Apr 2019 22:33:08 +0000 (17:33 -0500)]
Add additional parsing to extract the "MariaDB" keyword from version string
Enhanced MySQL/MariaDB version string parsing to accommodate for exotic
MariaDB version strings where the "MariaDB" word is embedded among other
alphanumeric characters such as "MariaDBV1". This detection is critical in
order to correctly accomodate for API features that have split between MySQL
and MariaDB such as the "transaction_isolation" system variable.
Mike Bayer [Sat, 13 Apr 2019 03:44:42 +0000 (23:44 -0400)]
Use pytest items in custom collection
We have a custom test collection hook that did not take
node of the actual list of functions in items. By looking
in this list we now support the class/function arguments
passed to the py.test command line.
Mike Bayer [Wed, 10 Apr 2019 15:51:27 +0000 (11:51 -0400)]
Don't use and_() inside of Query.filter_by
Adjusted the :meth:`.Query.filter_by` method to not call :func:`.and()`
internally against multiple criteria, instead passing it off to
:meth:`.Query.filter` as a series of criteria, instead of a single criteria.
This allows :meth:`.Query.filter_by` to defer to :meth:`.Query.filter`'s
treatment of variable numbers of clauses, including the case where the list
is empty. In this case, the :class:`.Query` object will not have a
``.whereclause``, which allows subsequent "no whereclause" methods like
:meth:`.Query.select_from` to behave consistently.
Mike Bayer [Tue, 9 Apr 2019 21:38:53 +0000 (17:38 -0400)]
Add __reduce_ex__ to MutableList; add compat for older pickles
Fixed bug where using ``copy.copy()`` or ``copy.deepcopy()`` on
:class:`.MutableList` would cause the items within the list to be
duplicated, due to an inconsistency in how Python pickle and copy both make
use of ``__getstate__()`` and ``__setstate__()`` regarding lists. In order
to resolve, a ``__reduce_ex__`` method had to be added to
:class:`.MutableList`. In order to maintain backwards compatibility with
existing pickles based on ``__getstate__()``, the ``__setstate__()`` method
remains as well; the test suite asserts that pickles made against the old
version of the class can still be deserialized by the pickle module.
Also modified sqlalchemy.testing.util.picklers to return picklers all the way through
pickle.HIGHEST_PROTOCOL.
Mike Bayer [Tue, 9 Apr 2019 13:16:16 +0000 (09:16 -0400)]
Propagate query-arg-only URL to psycopg2; don't send blank host
Fixed regression from release 1.3.2 caused by :ticket:`4562` where a URL
that contained only a query string and no hostname, such as for the
purposes of specifying a service file with connection information, would no
longer be propagated to psycopg2 properly. The change in :ticket:`4562`
has been adjusted to further suit psycopg2's exact requirements, which is
that if there are any connection parameters whatsoever, the "dsn" parameter
is no longer required, so in this case the query string parameters are
passed alone.
Mike Bayer [Fri, 5 Apr 2019 01:43:12 +0000 (21:43 -0400)]
Enhance documentation for string compilation use cases
- Add a web link for UnsupportedCompilationError
- Add new section to errors.rst
- add more detail and cross-linking to the FAQ
- include security caveats for parameter rendering
Matt Lewellyn [Wed, 3 Apr 2019 22:39:15 +0000 (18:39 -0400)]
MSSQL: only compile ORDER BY if it will be rendered
Fixed issue in SQL Server dialect where if a bound parameter were present in
an ORDER BY expression that would ultimately not be rendered in the SQL
Server version of the statement, the parameters would still be part of the
execution parameters, leading to DBAPI-level errors. Pull request courtesy
Matt Lewellyn.