Mike Bayer [Wed, 22 Jan 2020 21:27:26 +0000 (16:27 -0500)]
InstanceState default path is RootRegistry, not tuple
Fixed regression caused in 1.3.13 by :ticket:`5056` where a refactor of the
ORM path registry system made it such that a path could no longer be
compared to an empty tuple, which can occur in a particular kind of joined
eager loading path. The "empty tuple" use case has been resolved so that
the path registry is compared to a path registry in all cases; the
:class:`.PathRegistry` object itself now implements ``__eq__()`` and
``__ne__()`` methods which will take place for all equality comparisons and
continue to succeed in the not anticipated case that a non-
:class:`.PathRegistry` object is compared, while emitting a warning that
this object should not be the subject of the comparison.
Mike Bayer [Wed, 22 Jan 2020 16:01:59 +0000 (11:01 -0500)]
Clarify documentation for lazy_loaded_from
This attribute was never available in conjunction with
mapper options, and additionally the use of baked queries
in the lazy loader strategy prevent this attribute from
being reliably available within the before_compile hook
unless baked queries are turned off entirely.
Mike Bayer [Tue, 21 Jan 2020 23:41:48 +0000 (18:41 -0500)]
Reorganize core event modules to avoid import cycles
sqlalchemy.sql.naming was causing a full import of
engine due to the DDLEvents dependency. Break out pool,
DDL and engine events into new modules specific to those
packages; resolve some other import cycles in Core also.
Mike Bayer [Mon, 20 Jan 2020 17:41:22 +0000 (12:41 -0500)]
Adjust natural path to relationship's base mapper for aliased class also
Fixed regression in loader options introduced in 1.3.0b3 via :ticket:`4468`
where the ability to create a loader option using
:meth:`.PropComparator.of_type` targeting an aliased entity that is an
inheriting subclass of the entity which the preceding relationship refers
to would fail to produce a matching path. See also :ticket:`5082` fixed
in this same release which involves a similar kind of issue.
Gord Thompson [Thu, 19 Dec 2019 17:20:39 +0000 (12:20 -0500)]
Improve regex parsing of CHECK constraints for PostgreSQL.
Fixed issue where the PostgreSQL dialect would fail to parse a reflected
CHECK constraint that was a boolean-valued function (as opposed to a
boolean-valued expression).
Mike Bayer [Fri, 17 Jan 2020 22:31:41 +0000 (17:31 -0500)]
Remove jython code, remove all jython / pypy symbols
Removed all dialect code related to support for Jython and zxJDBC. Jython
has not been supported by SQLAlchemy for many years and it is not expected
that the current zxJDBC code is at all functional; for the moment it just
takes up space and adds confusion by showing up in documentation. At the
moment, it appears that Jython has achieved Python 2.7 support in its
releases but not Python 3. If Jython were to be supported again, the form
it should take is against the Python 3 version of Jython, and the various
zxJDBC stubs for various backends should be implemented as a third party
dialect.
Additionally modernized logic that distinguishes between "cpython"
and "pypy" to instead look at platform.python_distribution() which
reliably tells us if we are cPython or not; all booleans which
previously checked for pypy and sometimes jython are now converted
to be "not cpython", this impacts the test suite for tests that are
cPython centric.
Mike Bayer [Fri, 17 Jan 2020 19:31:10 +0000 (14:31 -0500)]
apply asbool reduction to the onclause in join()
The :func:`.true` and :func:`.false` operators may now be applied as the
"onclause" of a :func:`.sql.join` on a backend that does not support
"native boolean" expressions, e.g. Oracle or SQL Server, and the expression
will render as "1=1" for true and "1=0" false. This is the behavior that
was introduced many years ago in :ticket:`2804` for and/or expressions.
Mike Bayer [Tue, 14 Jan 2020 22:32:12 +0000 (17:32 -0500)]
Establish that contains_eager()->alias can be replaced by of_type
One test in test_of_type was creating a cartesian product
because contains_eager() was used with "alias" to refer
to a with_polymorphic(), but the wp was not used with of_type(),
so the pathing did not know that additional entities were present.
while the docs indicate that of_type() should be used, there is no
reason to use "alias" when you are using of_type(). Attempts
to make this automatic don't work as the current usage contract
with "alias" is that the contains_eager() chain can continue
along in terms of the base entities, which is another example
of the implicit swapping of entities for an aliased version of
themselves that really should be entirely marked as deprecated
throughout 1.4 and removed in 2.0.
So instead, add test coverage for the of_type() versions of
things and begin to make the case that we can remove "alias"
entirely, where previously we thought we would only deprecate
the string form.
Mike Bayer [Mon, 13 Jan 2020 18:50:38 +0000 (13:50 -0500)]
Adjust use_mapper_path rule for poly subclasses
We must change the approach from 2734439 as the information
loss is breaking subquery eager loading.
Move the adjustment into a deeper set of logic inside
of path_regsitry. We can distinguish between a path
that will "naturally" build from an aliased entity
at the base, vs. one that will "naturally" build
on all raw mappers, based on if when we observe that
we are being given a with_polymorphic(), if the existing
parent path is already in progress or not.
In general, we prefer paths to have as much of the original
information as possible, and the "natural path" is supposed
to be where the loader lookup stuff happens.
Mike Bayer [Fri, 10 Jan 2020 18:16:43 +0000 (13:16 -0500)]
Fixes for table-bound version_id_col against mapped selectable
Fixed bug where a versioning column specified on a mapper against a
:func:`.select` construct where the version_id_col itself were against the
underlying table would incur additional loads when accessed, even if the
value were locally persisted by the flush. The actual fix is a result of
the changes in :ticket:`4617`, by fact that a :func:`.select` object no
longer has a ``.c`` attribute and therefore does not confuse the mapper
into thinking there's an unknown column value present.
Fixed bug in ORM versioning feature where assignment of an explicit
version_id for a counter configured against a mapped selectable where
version_id_col is against the underlying table would fail if the previous
value were expired; this was due to the fact that the mapped attribute
would not be configured with active_history=True.
Mike Bayer [Fri, 10 Jan 2020 18:16:43 +0000 (13:16 -0500)]
Integrate mapper-level version_id_col with versioned_history
as the versioned_history example supplies an integer version
counter for the purposes of generating an audit trail, this
counter is also suited to be used for optimistic concurrency
detection using the version_id_col feature. Build upon
the test that was first added in ac54ba0f2d8df5a76b6852841b6b3321c0e6c0e2
to provide a flag and some basic documentation.
Mike Bayer [Fri, 10 Jan 2020 15:30:13 +0000 (10:30 -0500)]
Alter unique bound parameter key on deserialize
Fixed bug in sqlalchemy.ext.serializer where a unique
:class:`.BindParameter` object could conflict with itself if it were
present in the mapping itself, as well as the filter condition of the
query, as one side would be used against the non-deserialized version and
the other side would use the deserialized version. Logic is added to
:class:`.BindParameter` similar to its "clone" method which will uniquify
the parameter name upon deserialize so that it doesn't conflict with its
original.
Mike Bayer [Tue, 7 Jan 2020 02:06:10 +0000 (21:06 -0500)]
Set use_mapper_path=True for with_poly subentities
Fixed regression in joined eager loading introduced in 1.3.0b3 via
:ticket:`4468` where the ability to create a joined option across a
:func:`.with_polymorphic` into a polymorphic subclass using
:meth:`.RelationshipProperty.of_type` and then further along regular mapped
relationships would fail as the polymorphic subclass would not add itself
to the load path in a way that could be located by the loader strategy. A
tweak has been made to resolve this scenario.
Mike Bayer [Mon, 6 Jan 2020 19:09:01 +0000 (14:09 -0500)]
Support GenericFunction.name passed as a quoted_name
A function created using :class:`.GenericFunction` can now specify that the
name of the function should be rendered with or without quotes by assigning
the :class:`.quoted_name` construct to the .name element of the object.
Prior to 1.3.4, quoting was never applied to function names, and some
quoting was introduced in :ticket:`4467` but no means to force quoting for
a mixed case name was available. Additionally, the :class:`.quoted_name`
construct when used as the name will properly register its lowercase name
in the function registry so that the name continues to be available via the
``func.`` registry.
Mike Bayer [Wed, 1 Jan 2020 23:24:03 +0000 (18:24 -0500)]
Enable F821
In Ia63a510f9c1d08b055eef62cf047f1f427f0450c we introduced
"lambda combinations" which use a bit of function closure inspection
in order to allow for testing combinations that make use of symbols that
come from test fixtures, or from the test itself.
Two problems. One is that we can't use F821 flake8 rule without either
adding lots of noqas, skipping the file, or adding arguments to the
lambdas themselves that are then populated, which makes for a very
verbose system. The other is that the system is already verbose
with all those lambdas and the magic in use is a non-explicit kind,
hence F821 reminds us that if we can improve upon this, we should.
So let's improve upon it by making it so that the "lambda" is just
once and up front for the whole thing, and let it accept the arguments
directly. This still requires magic, because these test cases need
to resolve at test collection time, not test runtime. But we will
instead substitute a namespace up front that can be coerced into
its desired form within the tests.
Additionally, there's a little bit of py2k compatible type annotations
present; f821 is checking these, so we have to add those imports
also using the TYPE_CHECKING boolean so they don't take place in
py2k.
Mike Bayer [Fri, 3 Jan 2020 17:10:57 +0000 (12:10 -0500)]
Fix cext for Python 2; ensure C extensions build successfully
The C extensions have been broken since cc718cccc0bf8a01abdf4068c
however CI did not find this, because the build degraded to
non-C extensions without failing. Ensure that if cext is set,
there is no fallback to non-cext build if the C extension build
fails.
As C extensions have been silently failing on 2.7 for some commits,
the callcounts also needed to be adjusted for recent performance-related
changes. That in turn required a fix to the profiling decorator
to use signature rewriting in order to support py.test's
fixture mechanism under Python 2, usage introduced under profiling
in 89bf6d80a9.
Mike Bayer [Thu, 2 Jan 2020 17:48:23 +0000 (12:48 -0500)]
Implement explicit autobegin step for Session
The :class:`.Session` object no longer initates a
:class:`.SessionTransaction` object immediately upon construction or after
the previous transaction is closed; instead, "autobegin" logic now
initiates the new :class:`.SessionTransaction` on demand when it is next
needed. Rationale includes to remove reference cycles from a
:class:`.Session` that has been closed out, as well as to remove the
overhead incurred by the creation of :class:`.SessionTransaction` objects
that are often discarded immediately. This change affects the behavior of
the :meth:`.SessionEvents.after_transaction_create` hook in that the event
will be emitted when the :class:`.Session` first requires a
:class:`.SessionTransaction` be present, rather than whenever the
:class:`.Session` were created or the previous :class:`.SessionTransaction`
were closed. Interactions with the :class:`.Engine` and the database
itself remain unaffected.
Heckad [Wed, 1 Jan 2020 19:47:01 +0000 (14:47 -0500)]
Use context managers for threading.Lock()
(zzzeek:) For some reason I thought that threading.Lock() still did
not support context managers, at least in Python 2, however this
does not seem to be the case.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Closes: #5069
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5069
Pull-request-sha: efeac06dda5afdbe33abcf9b27c8b5b5725c8444
Gord Thompson [Tue, 31 Dec 2019 17:42:09 +0000 (12:42 -0500)]
Fix DATETIMEOFFSET formatting to preserve fractional seconds.
Fixed issue where a timezone-aware ``datetime`` value being converted to
string for use as a parameter value of a :class:`.mssql.DATETIMEOFFSET`
column was omitting the fractional seconds.
Federico Caselli [Tue, 31 Dec 2019 01:29:33 +0000 (20:29 -0500)]
Fix test failures under Windows
Fixed a few test failures which would occur on Windows due to SQLite file
locking issues, as well as some timing issues in connection pool related
tests; pull request courtesy Federico Caselli.
Note the pool related issues were fixed by Mike in
I1a7162e67912d22c135fa517b687a073f8fd9151 but are being ticketed
here.
Mike Bayer [Tue, 31 Dec 2019 16:53:07 +0000 (11:53 -0500)]
Repair uncovered warning in persistnce.py; update versioning tests
Repaired a warning in the ORM flush process that was not covered by test
coverage when deleting objects that use the "version_id" feature. This
warning is generally unreachable unless using a dialect that sets the
"supports_sane_rowcount" flag to False, which is not typically the case
however is possible for some MySQL configurations as well as older Firebird
drivers, and likely some third party dialects.
As part of this change, we would like to establish that versionining-
related warnings are not expected to emit for the core set of
test-covered dialects, and if they are we would like the check for
warning emitted to be explicit, rather than an ignore.
Mike Bayer [Tue, 31 Dec 2019 18:01:59 +0000 (13:01 -0500)]
Bump test_build_query numbers
Due to the decreased caching introduced in
Ifd93856eba550483f95f9ae63d49f36ab068b85a, callcounts have risen
here however they did not pass the threshold in the review.
Bump them now instead.
Mike Bayer [Tue, 31 Dec 2019 01:01:23 +0000 (20:01 -0500)]
Fix newly found rst issue
Likely due to new versions flake8-rst-docstrings or similar,
repair an incorrectly formatted code example in a doc string
causing all the gerrits to fail.
Mike Bayer [Mon, 30 Dec 2019 18:08:17 +0000 (13:08 -0500)]
Include GROUP BY in _should_nest_selectable criteria
Fixed bug where usage of joined eager loading would not properly wrap the
query inside of a subquery when :meth:`.Query.group_by` were used against
the query. When any kind of result-limiting approach is used, such as
DISTINCT, LIMIT, OFFSET, joined eager loading embeds the row-limited query
inside of a subquery so that the collection results are not impacted. For
some reason, the presence of GROUP BY was never included in this criterion,
even though it has a similar effect as using DISTINCT. Additionally, the
bug would prevent using GROUP BY at all for a joined eager load query for
most database platforms which forbid non-aggregated, non-grouped columns
from being in the query, as the additional columns for the joined eager
load would not be accepted by the database.
Mike Bayer [Sun, 29 Dec 2019 07:09:04 +0000 (02:09 -0500)]
De-implement non-working / testing copy_internals from dml
The DML constructs will need to have traverse_internals
symbols set up; as there are currently non-working /non-used
_copy_internals methods, just remove these for now as they
are unlikely to be working correctly in any case.
Additionally remove an errant "return" statement noted
on the same issue from the MySQL dialect.
Federico Caselli [Sun, 29 Dec 2019 02:23:23 +0000 (21:23 -0500)]
Improve two phase transaction requirement detection for PG
Improved detection of two phase transactions requirement for the PostgreSQL
database by testing that max_prepared_transactions is set to a value
greater than 0. Pull request courtesy Federico Caselli.
Carson Ip [Fri, 27 Dec 2019 17:05:30 +0000 (12:05 -0500)]
Fix WeakSequence circular reference
Fixed a reference cycle which could impact the GC behavior of the
:class:`.WeakSequence` object, currently used within one place in certain
mapper configurations. The issue only affects configuration-time
structures. Pull request courtesy Carson Ip.
Mike Bayer [Fri, 27 Dec 2019 19:10:36 +0000 (14:10 -0500)]
Note time passage requirement for pool.invalidate()
For Windows, time.time() may only have 16 millisecond
accuracy, so invalidation routines which compare
the time.time() of invalidate() to the time.time() when
the ConnectionRecord last connected may fail in a unit test
environment that does not pause at least this much time
since the ConnectionRecord startup. Using >= for comparison
instead of > was considered but this only leads to more confusing
results as the ConnecitonRecord goes into a re-connect loop
as time continues to not pass.
Overall, while using routines such as Python 3.7's time_ns()
might be helpful, for now make sure tests which rely on this
are marked under timing intensive and add small sleeps.
Mike Bayer [Mon, 9 Dec 2019 23:05:00 +0000 (18:05 -0500)]
Use expanding IN for all literal value IN expressions
The "expanding IN" feature, which generates IN expressions at query
execution time which are based on the particular parameters associated with
the statement execution, is now used for all IN expressions made against
lists of literal values. This allows IN expressions to be fully cacheable
independently of the list of values being passed, and also includes support
for empty lists. For any scenario where the IN expression contains
non-literal SQL expressions, the old behavior of pre-rendering for each
position in the IN is maintained. The change also completes support for
expanding IN with tuples, where previously type-specific bind processors
weren't taking effect.
As part of this change, a more explicit separation between
"literal execute" and "post compile" bound parameters is being made;
as the "ansi bind rules" feature is rendering bound parameters
inline, as we now support "postcompile" generically, these should
be used here, however we have to render literal values at
execution time even for "expanding" parameters. new test fixtures
etc. are added to assert everything goes to the right place.
Mike Bayer [Fri, 20 Dec 2019 16:40:10 +0000 (11:40 -0500)]
Copy bind_processors when altering for expanding IN
Fixed issue where the collection of value processors on a
:class:`.Compiled` object would be mutated when "expanding IN" parameters
were used with a datatype that has bind value processors; in particular,
this would mean that when using statement caching and/or baked queries, the
same compiled._bind_processors collection would be mutated concurrently.
Since these processors are the same function for a given bind parameter
namespace every time, there was no actual negative effect of this issue,
however, the execution of a :class:`.Compiled` object should never be
causing any changes in its state, especially given that they are intended
to be thread-safe and reusable once fully constructed.
Mike Bayer [Fri, 20 Dec 2019 15:17:17 +0000 (10:17 -0500)]
Ensure comparison includes "don't compare values" feature
upcoming changes for "expanding IN in all cases" and
"lambda elements" both rely upon comparisons that work
across changing bound values, so commit the testing fixture
ahead of time. Additionally, repair the feature itself
within traversals.
Mike Bayer [Thu, 19 Dec 2019 02:50:24 +0000 (21:50 -0500)]
Don't apply aliasing + adaption for simple relationship joins
Identified a performance issue in the system by which a join is constructed
based on a mapped relationship. The clause adaption system would be used
for the majority of join expressions including in the common case where no
adaptation is needed. The conditions under which this adaptation occur
have been refined so that average non-aliased joins along a simple
relationship without a "secondary" table use about 70% less function calls.
Mike Bayer [Thu, 19 Dec 2019 14:19:53 +0000 (09:19 -0500)]
Improve documentation for refresh_flush event
This event does not include INSERTed primary key columns
and additionally will always be limited to default/onupdate
columns. Note better choices for interception of INSERT
events.
Added support for prefixes to the :class:`.CTE` construct, to allow
support for Postgresql 12 "MATERIALIZED" and "NOT MATERIALIZED" phrases.
Pull request courtesy Marat Sharafutdinov.
Mike Bayer [Mon, 16 Dec 2019 21:38:06 +0000 (16:38 -0500)]
Do the CompoundSelect check for number of columns in the compile phase
Starting to go forward with the general idea of moving more
of Core / ORM construction into the compile phase. Bigger
initiatives like the refactor of Query will follow onto this.
Mike Bayer [Fri, 13 Dec 2019 17:44:23 +0000 (12:44 -0500)]
Close connection if begin fails
Fixed issue where by if the "begin" of a transaction failed at the Core
engine/connection level, such as due to network error or database is locked
for some transactional recipes, within the context of the :class:`.Session`
procuring that connection from the connection pool and then immediately
returning it, the ORM :class:`.Session` would not close the connection
despite this connection not being stored within the state of that
:class:`.Session`. This would lead to the connection being cleaned out by
the connection pool weakref handler within garbage collection which is an
unpreferred codepath that in some special configurations can emit errors in
standard error.
Mike Bayer [Fri, 6 Dec 2019 16:38:55 +0000 (11:38 -0500)]
Use label reference coercion for select() distinct keyword argument
Fixed bug where "distinct" keyword passed to :func:`.select` would not
treat a string value as a "label reference" in the same way that the
:meth:`.select.distinct` does; it would instead raise unconditionally. This
keyword argument and the others passed to :func:`.select` will ultimately
be deprecated for SQLAlchemy 2.0.
Mike Bayer [Fri, 6 Dec 2019 15:24:25 +0000 (10:24 -0500)]
Include DISTINCT in error message for label reference
Needed to add tests to ensure this label reference is handled
correctly, so also modified the exception message to
be more clear if someone has this error within distinct().
Mike Bayer [Thu, 5 Dec 2019 00:18:57 +0000 (19:18 -0500)]
Introduce lambda combinations
As the ORM's combinatoric tests mostly use entities and
table metadata that's defined in fixtures, we can't use
@testing.combinations directly as it takes place at the
module level. Instead we use lambdas, but to reduce
verbosity we use a code replacement so that the namespace
of the lambda can be provided at runtime rather than
module import time.
Mike Bayer [Mon, 2 Dec 2019 16:47:08 +0000 (11:47 -0500)]
Skip sub-minute timezone tests for Python 3 < 3.7
The datetime.timezone class as of Python 3.7, or SQLAlchemy's port for Python
2, supports seconds and microseconds. For Python 3.6 and earlier, it is not
supported.
Gord Thompson [Tue, 26 Nov 2019 14:57:48 +0000 (09:57 -0500)]
Add DATETIMEOFFSET support for mssql+pyodbc
Repaired support for the :class:`.mssql.DATETIMEOFFSET` datatype on PyODBC,
by adding PyODBC-level result handlers as it does not include native
support for this datatype. This includes usage of the Python 3 "timezone"
tzinfo subclass in order to set up a timezone, which on Python 2 makes
use of a minimal backport of "timezone" in sqlalchemy.util.
Mike Bayer [Fri, 29 Nov 2019 15:50:44 +0000 (10:50 -0500)]
Gracefully degrade for SQLite JSON receiving direct numeric value
Fixed issue to workaround SQLite's behavior of assigning "numeric" affinity
to JSON datatypes, first described at :ref:`change_3850`, which returns
scalar numeric JSON values as a number and not as a string that can be JSON
deserialized. The SQLite-specific JSON deserializer now gracefully
degrades for this case as an exception and bypasses deserialization for
single numeric values, as from a JSON perspective they are already
deserialized.
Also adds a combinatoric fixture for JSON single values within
the dialect-general test suite.
Mike Bayer [Tue, 26 Nov 2019 16:09:00 +0000 (11:09 -0500)]
Don't clear metadata in TablesTest setup
Some upcoming commits will make use of @metadata_fixture
within a TablesTest class. As the fixture takes place before
setup, remove anything in setup that would interfere with it.
Gord Thompson [Thu, 21 Nov 2019 14:43:40 +0000 (09:43 -0500)]
Add sequence support for MariaDB 10.3+.
Added support for use of the :class:`.Sequence` construct with MariaDB 10.3
and greater, as this is now supported by this database. The construct
integrates with the :class:`.Table` object in the same way that it does for
other databases like PostrgreSQL and Oracle; if is present on the integer
primary key "autoincrement" column, it is used to generate defaults. For
backwards compatibility, to support a :class:`.Table` that has a
:class:`.Sequence` on it to support sequence only databases like Oracle,
while still not having the sequence fire off for MariaDB, the optional=True
flag should be set, which indicates the sequence should only be used to
generate the primary key if the target database offers no other option.
Mike Bayer [Mon, 25 Nov 2019 20:09:47 +0000 (15:09 -0500)]
Remove ORM elements from annotations at the schema level.
Fixed issue where when constructing constraints from ORM-bound columns,
primarily :class:`.ForeignKey` objects but also :class:`.UniqueConstraint`,
:class:`.CheckConstraint` and others, the ORM-level
:class:`.InstrumentedAttribute` is discarded entirely, and all ORM-level
annotations from the columns are removed; this is so that the constraints
are still fully pickleable without the ORM-level entities being pulled in.
These annotations are not necessary to be present at the schema/metadata
level.
Fully implemented coercions for constraint columns within
schema.py, including for FK referenced columns.
Mike Bayer [Sat, 23 Nov 2019 17:25:20 +0000 (12:25 -0500)]
Generalize DescriptorProps.uses_objects
Previously, uses_objects was specific to the SynonymAttribute;
generalize it so that it defaults to False for other DescriptorProps.
Immediate fix is against CompositeProperty.
Fixed regression introduced in 1.3.0 related to the association proxy
refactor in :ticket:`4351` that prevented :func:`.composite` attributes
from working in terms of an association proxy that references them.
Add test coverage for association proxies that refer to Composite
attributes as endpoints.
Mike Bayer [Fri, 22 Nov 2019 19:28:21 +0000 (14:28 -0500)]
Raise for persistence casades set with viewonly=True
An error is raised if any persistence-related "cascade" settings are made
on a :func:`.relationship` that also sets up viewonly=True. The "cascade"
settings now default to non-persistence related settings only when viewonly
is also set. This is the continuation from :ticket:`4993` where this
setting was changed to emit a warning in 1.3.
Mike Bayer [Wed, 20 Nov 2019 17:15:57 +0000 (12:15 -0500)]
Warn for settings that don't work with viewonly=True
Setting persistence-related flags on :func:`.relationship` while also
setting viewonly=True will now emit a regular warning, as these flags do
not make sense for a viewonly=True relationship. In particular, the
"cascade" settings have their own warning that is generated based on the
individual values, such as "delete, delete-orphan", that should not apply
to a viewonly relationship. Note however that in the case of "cascade",
these settings are still erroneously taking effect even though the
relationship is set up as "viewonly". In 1.4, all persistence-related
cascade settings will be disallowed on a viewonly=True relationship in
order to resolve this issue.
Mike Bayer [Fri, 22 Nov 2019 15:27:02 +0000 (10:27 -0500)]
Don't raise w/ raiseload strategy for many-to-one history in flush
Fixed issue involving ``lazy="raise"`` strategy where an ORM delete of an
object would raise for a simple "use-get" style many-to-one relationship
that had lazy="raise" configured. This is inconsistent vs. the change
introduced in 1.3 as part of :ticket:`4353`, where it was established that
a history operation that does not expect emit SQL should bypass the
``lazy="raise"`` check, and instead effectively treat it as
``lazy="raise_on_sql"`` for this case. The fix adjusts the lazy loader
strategy to not raise for the case where the lazy load was instructed that
it should not emit SQL if the object were not present.
Mike Bayer [Tue, 19 Nov 2019 14:30:31 +0000 (09:30 -0500)]
Skip on slice assignment to self
Fixed issue where when assigning a collection to itself as a slice, the
mutation operation would fail as it would first erase the assigned
collection inadvertently. As an assignment that does not change the
contents should not generate events, the operation is now a no-op. Note
that the fix only applies to Python 3; in Python 2, the ``__setitem__``
hook isn't called in this case; ``__setslice__`` is used instead which
recreates the list item-by-item in all cases.