Mike Bayer [Tue, 6 Jun 2017 22:53:03 +0000 (18:53 -0400)]
- assert passive_deletes='all' does not affect collection/scalar
membership removal
in issue #3844 we hypotheized that passive_deletes='all' was broken
because it sets to NULL a foreign key attribute when the child
object is removed or replaced. However, not doing the NULL
set means that nothing happens at all and the operation silently
fails.
Mike Bayer [Tue, 6 Jun 2017 21:13:54 +0000 (17:13 -0400)]
Warn when declared_attr.cascading detected on mapped class
A warning is emitted if the :attr:`.declared_attr.cascading` modifier
is used with a declarative attribute that is itself declared on
a class that is to be mapped, as opposed to a declarative mixin
class or ``__abstract__`` class. The :attr:`.declared_attr.cascading`
modifier currently only applies to mixin/abstract classes.
Also add a test for @declared_attr.cascading when used on an attribute
on __abstract__.
Mike Bayer [Tue, 6 Jun 2017 17:54:33 +0000 (13:54 -0400)]
Re-send column value w/ onupdate default during post-update
Adjusted the behavior of post_update such that if a column with
an "onupdate" default has received an explicit value for
INSERT, re-send the same data during a post-update UPDATE so
that the value remains in effect, rather than an onupdate
overwriting it.
Mike Bayer [Tue, 12 Apr 2016 19:56:02 +0000 (15:56 -0400)]
Implement _postfetch_post_update to expire/refresh onupdates in post_update
Fixed bug involving the :paramref:`.relationship.post_update` feature
where a column "onupdate" value would not result in expiration or
refresh of the corresponding object attribute, if the UPDATE for the
row were a result of the "post update" feature. Additionally, the
:meth:`.SessionEvents.refresh_flush` event is now emitted for these
attributes when refreshed within the flush.
Mike Bayer [Mon, 5 Jun 2017 19:49:04 +0000 (15:49 -0400)]
Implement in-place mutation operators for MutableSet, MutableList
Implemented in-place mutation operators ``__ior__``, ``__iand__``,
``__ixor__`` and ``__isub__`` for :class:`.mutable.MutableSet`
and ``__iadd__`` for :class:`.mutable.MutableList` so that change
events are fired off when these mutator methods are used to alter the
collection.
Mike Bayer [Tue, 28 Mar 2017 15:00:37 +0000 (11:00 -0400)]
selectin polymorphic loading
Added a new style of mapper-level inheritance loading
"polymorphic selectin". This style of loading
emits queries for each subclass in an inheritance
hierarchy subsequent to the load of the base
object type, using IN to specify the desired
primary key values.
Mike Bayer [Fri, 26 May 2017 17:26:40 +0000 (13:26 -0400)]
Don't hard-evaluate non-ORM @declared_attr for AbstractConcreteBase
Fixed bug where using :class:`.declared_attr` on an
:class:`.AbstractConcreteBase` where a particular return value were some
non-mapped symbol, including ``None``, would cause the attribute
to hard-evaluate just once and store the value to the object
dictionary, not allowing it to invoke for subclasses. This behavior
is normal when :class:`.declared_attr` is on a mapped class, and
does not occur on a mixin or abstract class. Since
:class:`.AbstractConcreteBase` is both "abstract" and actually
"mapped", a special exception case is made here so that the
"abstract" behavior takes precedence for :class:`.declared_attr`.
Mike Bayer [Fri, 26 May 2017 15:24:25 +0000 (11:24 -0400)]
Add placeholder XML support
Added a placeholder type :class:`.mssql.XML` to the SQL Server
dialect, so that a reflected table which includes this type can
be re-rendered as a CREATE TABLE. The type has no special round-trip
behavior nor does it currently support additional qualifying
arguments.
Michael Birtwell [Thu, 25 May 2017 15:11:21 +0000 (11:11 -0400)]
Flatten operator precedence for comparison operators
The operator precedence for all comparison operators such as LIKE, IS,
IN, MATCH, equals, greater than, less than, etc. has all been merged
into one level, so that expressions which make use of these against
each other will produce parentheses between them. This suits the
stated operator precedence of databases like Oracle, MySQL and others
which place all of these operators as equal precedence, as well as
Postgresql as of 9.5 which has also flattened its operator precendence.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #3999
Change-Id: I3f3d5124a64af0d376361cdf15a97e2e703be56f
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/367
Mike Bayer [Thu, 25 May 2017 14:17:11 +0000 (10:17 -0400)]
Raise if ForeignKeyConstraint created with different numbers of
local and remote columns.
An :class:`.ArgumentError` is now raised if a
:class:`.ForeignKeyConstraint` object is created with a mismatched
number of "local" and "remote" columns, which otherwise causes the
internal state of the constraint to be incorrect. Note that this
also impacts the condition where a dialect's reflection process
produces a mismatched set of columns for a foreign key constraint.
Downstream DB2 dialect has been reported as potentially causing this
scenario.
Mike Bayer [Mon, 15 May 2017 13:39:19 +0000 (09:39 -0400)]
Add with_for_update() support in session.refresh()
Session.refresh() is still hardcoded to legacy lockmode,
come up with a new API so that the newer argument style
works with it.
Added new argument :paramref:`.with_for_update` to the
:meth:`.Session.refresh` method. When the :meth:`.Query.with_lockmode`
method were deprecated in favor of :meth:`.Query.with_for_update`,
the :meth:`.Session.refresh` method was never updated to reflect
the new option.
Mike Bayer [Tue, 23 May 2017 14:17:51 +0000 (10:17 -0400)]
Remove twophase for cx_Oracle 6.x
Support for two-phase transactions has been removed entirely for
cx_Oracle when version 6.0b1 or later of the DBAPI is in use. The two-
phase feature historically has never been usable under cx_Oracle 5.x in
any case, and cx_Oracle 6.x has removed the connection-level "twophase"
flag upon which this feature relied.
Mike Bayer [Mon, 22 May 2017 19:42:59 +0000 (15:42 -0400)]
Add AttributeEvents.modified
Added new event handler :meth:`.AttributeEvents.modified` which is
triggered when the func:`.attributes.flag_modified` function is
invoked, which is common when using the :mod:`sqlalchemy.ext.mutable`
extension module.
Mike Bayer [Mon, 22 May 2017 19:08:10 +0000 (15:08 -0400)]
Add clause adaptation for AliasedClass to with_parent()
Fixed bug where :meth:`.Query.with_parent` would not work if the
:class:`.Query` were against an :func:`.aliased` construct rather than
a regular mapped class. Also adds a new parameter
:paramref:`.util.with_parent.from_entity` to the standalone
:func:`.util.with_parent` function as well as
:meth:`.Query.with_parent`.
Kataev Denis [Mon, 22 May 2017 21:52:45 +0000 (17:52 -0400)]
Repair formatting throughout documentation
1. Section decorators to [one style](http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#sections):
without inset at both side and with same length as text.
2. Fix broken [reference](http://docs.sqlalchemy.org/en/latest/core/type_basics.html#generic-types).
3. Convert tabs to space in some small files.
4. Some python code snippets have python+sql syntax hint.
Diana Clarke [Tue, 14 Mar 2017 17:03:11 +0000 (13:03 -0400)]
detect and raise for version_id is NULL
The versioning feature does not support NULL for the version counter.
An exception is now raised if the version id is programmatic and
was set to NULL for an UPDATE. Pull request courtesy Diana Clarke.
Mike Bayer [Mon, 22 May 2017 18:08:55 +0000 (14:08 -0400)]
Allow metadata.reflect() to recover from unreflectable tables
Added support for views that are unreflectable due to stale
table definitions, when calling :meth:`.MetaData.reflect`; a warning
is emitted for the table that cannot respond to ``DESCRIBE``
but the operation succeeds. The MySQL dialect now
raises UnreflectableTableError which is in turn caught by
MetaData.reflect(). Reflecting the view standalone raises
this error directly.
Mike Bayer [Mon, 22 May 2017 18:47:26 +0000 (14:47 -0400)]
Detect no params w/ manual version_id counter and set to itself
Fixed bug where programmatic version_id counter in conjunction with
joined table inheritance would fail if the version_id counter
were not actually incremented and no other values on the base table
were modified, as the UPDATE would have an empty SET clause. Since
programmatic version_id where version counter is not incremented
is a documented use case, this specific condition is now detected
and the UPDATE now sets the version_id value to itself, so that
concurrency checks still take place.
Mike Bayer [Mon, 22 May 2017 17:00:38 +0000 (13:00 -0400)]
Remove "scope" keyword from scoped_session.__call__()
Removed a very old keyword argument from :class:`.scoped_session`
called ``scope``. This keyword was never documented and was an
early attempt at allowing for variable scopes.
Mike Bayer [Sun, 21 May 2017 19:28:00 +0000 (15:28 -0400)]
Prevent SQL server isolation level from failing
Fixed bug where SQL Server transaction isolation must be fetched
from a different view when using Azure data warehouse, the query
is now attempted against both views and then a NotImplemented
is raised unconditionally if failure continues to provide the
best resiliency against future arbitrary API changes in new
SQL Server versions.
Mike Bayer [Thu, 18 May 2017 21:44:10 +0000 (17:44 -0400)]
- Document the most transparent way to set JSON.NULL for
a column default.
The JSON.NULL value is special in that while it is a Python-side
value, it represents "do this special behavior", and is not at all
like any other Python-side value for which normally, that's exactly
the type of data we want back. So in this case, encourage the user
to use a SQL expression that is exact, so in the ORM context, you get
back what was actually persisted in the column. There's some variants
of this such as literal(JSON.NULL, JSON) but text("'null'") is simpler.
Mike Bayer [Wed, 17 May 2017 17:05:04 +0000 (13:05 -0400)]
Add new configuration, inspection for baked queries
Added new flag :paramref:`.Session.enable_baked_queries` to the
:class:`.Session` to allow baked queries to be disabled
session-wide, reducing memory use. Also added new :class:`.Bakery`
wrapper so that the bakery returned by :paramref:`.BakedQuery.bakery`
can be inspected.
Mike Bayer [Wed, 17 May 2017 02:13:40 +0000 (22:13 -0400)]
- give SelectinLoader its own bakery, dont use mapper
level cache
- include SelectinLoader itself in the cache key, though
this is currently not critical
Mike Bayer [Tue, 16 May 2017 13:51:06 +0000 (09:51 -0400)]
modernize and repair inheritance examples
remarkably, the examples for concrete and single were still
using classical mappings. Ensure all three examples use
modern declarative patterns, each illustrate the identical set
of query operations. Use back_populates, flat=True for joins,
etc. ensure flake8 linting, correct links and add a link back
from newly reworked inheritance documentation.
Mike Bayer [Fri, 12 May 2017 16:01:53 +0000 (12:01 -0400)]
Demote innerjoin to outerjoin coming from with_polymorphic
a with_polymorphic, regardless of inheritance type, represents
multiple classes. A subclass that wants to joinedload with innerjoin=True
needs to be demoted to an outerjoin because the parent entity rows
might not be of that type. Looks more intuitive with a joined
inheritance load, but applies just as well to single or concrete.
Mike Bayer [Fri, 12 May 2017 14:53:54 +0000 (10:53 -0400)]
Cascade mappers in terms of the instance's mapper
Fixed a (extremely old) bug in cascade_mappers where the
first cascade we do is against the "self" mapper, and not the
one that actually corresponds to the state given. These are
different in the case where we start with a relationship
to a class, and the instance is of a subclass, which itself
can have relationships that aren't on the base mapper.
A pretty severe bug that somehow has avoided the radar
since the beginning.
Mike Bayer [Fri, 12 May 2017 13:23:44 +0000 (09:23 -0400)]
Add links to with_only_columns to Select.column, append_column
Provide a brief example for these two methods
indicating that typically a table-bound (or other selectable)
column is appended here, then link to with_only_columns
documentation which has in-depth guidelines already including
that one should not append columns from the current select to itself.
Mike Bayer [Mon, 1 May 2017 17:04:32 +0000 (13:04 -0400)]
Update inheritance documentation.
The inheritance documentation is confused, disorganized, and out
of date. Reorganize and clarify, in particular in preparation
for new inheritance features.
Mike Bayer [Wed, 10 May 2017 18:03:28 +0000 (14:03 -0400)]
Add conditionals specific to deferred for expire ro properties
Fixed bug where a :func:`.column_property` that is also marked as
"deferred" would be marked as "expired" during a flush, causing it
to be loaded along with the unexpiry of regular attributes even
though this attribute was never accessed.
Mike Bayer [Tue, 9 May 2017 16:17:04 +0000 (12:17 -0400)]
Use regexp to parse cx_oracle version string
Fixed bug in cx_Oracle dialect where version string parsing would
fail for cx_Oracle version 6.0b1 due to the "b" character. Version
string parsing is now via a regexp rather than a simple split.
Mike Bayer [Mon, 8 May 2017 22:36:57 +0000 (18:36 -0400)]
Protect against cls weakref becoming None
Protected against testing "None" as a class in the case where
declarative classes are being garbage collected and new
automap prepare() operations are taking place concurrently, very
infrequently hitting a weakref that has not been fully acted upon
after gc.
Mike Bayer [Fri, 5 May 2017 18:59:39 +0000 (14:59 -0400)]
- big rewrite of the Sequence documentation:
1. Sequence should be associated with MetaData always,
except in the really weird case someone is sharing a Sequence
among multiple metadatas. Make this a "best practice", end the
confusion of #3951, #3979
2. "optional" is not a thing people use, trim this way down
Mike Bayer [Fri, 5 May 2017 14:39:18 +0000 (10:39 -0400)]
- add another note re: 339e2c13b0fc8e95a47d00c0f8fc5afc4b6dff9a
which clarifies that ForeignKey circumvents this logic as a
"convenience". issue #3978 is updated to address trying to make
this consistent.
Mike Bayer [Thu, 27 Apr 2017 15:24:41 +0000 (11:24 -0400)]
Call proxied collection before invoking creator in associationlist.append()
Improved the association proxy list collection so that premature
autoflush against a newly created association object can be prevented
in the case where ``list.append()`` is being used, and a lazy load
would be invoked when the association proxy accesses the endpoint
collection. The endpoint collection is now accessed first before
the creator is invoked to produce the association object.
Mike Bayer [Thu, 27 Apr 2017 14:26:10 +0000 (10:26 -0400)]
Enforce boolean result type for all eq_, is_, isnot, comparison
Repaired issue where the type of an expression that used
:meth:`.ColumnOperators.is_` or similar would not be a "boolean" type,
instead the type would be "nulltype", as well as when using custom
comparison operators against an untyped expression. This typing can
impact how the expression behaves in larger contexts as well as
in result-row-handling.
Mike Bayer [Thu, 23 Mar 2017 21:55:43 +0000 (17:55 -0400)]
Add selectin loading
Adding a new kind of relationship loader that is
a cross between the "immediateload" and the "subquery"
eager loader, using an IN criteria to load related items
in bulk immediately after the lead query result is loaded.
Mike Bayer [Mon, 24 Apr 2017 20:19:08 +0000 (16:19 -0400)]
test / document postgresql_ops against a labeled expression
Since postgresql_ops explicitly states that it expects
string keys, to apply to a function call or expression one
needs to give the SQL expression a label that can be referred
to by name in the dictionary. test / document this.
Mike Bayer [Fri, 21 Apr 2017 17:35:38 +0000 (13:35 -0400)]
Add _negate() to Label to negate inner element
Fixed the negation of a :class:`.Label` construct so that the
inner element is negated correctly, when the :func:`.not_` modifier
is applied to the labeled expression.
Mike Bayer [Mon, 17 Apr 2017 16:02:18 +0000 (12:02 -0400)]
Accommodate for query._current_path in subq eager load join_depth
Fixed bug in subquery eager loading where the "join_depth" parameter
for self-referential relationships would not be correctly honored,
loading all available levels deep rather than correctly counting
the specified number of levels for eager loading.
Mike Bayer [Fri, 7 Apr 2017 18:18:22 +0000 (14:18 -0400)]
Use baked lazyloading by default
The ``lazy="select"`` loader strategy now makes used of the
:class:`.BakedQuery` query caching system in all cases. This
removes most overhead of generating a :class:`.Query` object and
running it into a :func:`.select` and then string SQL statement from
the process of lazy-loading related collections and objects. The
"baked" lazy loader has also been improved such that it can now
cache in most cases where query load options are used.
Mike Bayer [Wed, 12 Apr 2017 19:15:16 +0000 (15:15 -0400)]
- move a few memusage tests out of "backend". something is up w/ cx_Oracle
when the suite runs, such as a background thread or something like that,
which is affecting these tests a bit.
Mike Bayer [Wed, 12 Apr 2017 15:37:19 +0000 (11:37 -0400)]
Warn on _compiled_cache growth
Added warnings to the LRU "compiled cache" used by the :class:`.Mapper`
(and ultimately will be for other ORM-based LRU caches) such that
when the cache starts hitting its size limits, the application will
emit a warning that this is a performance-degrading situation that
may require attention. The LRU caches can reach their size limits
primarily if an application is making use of an unbounded number
of :class:`.Engine` objects, which is an antipattern. Otherwise,
this may suggest an issue that should be brought to the SQLAlchemy
developer's attention.
Additionally, adjusted the test_memusage algorithm again as the
previous one could still allow a growing memory size to be missed.
Mike Bayer [Tue, 11 Apr 2017 14:26:38 +0000 (10:26 -0400)]
Set up base ARRAY to be compatible with postgresql.ARRAY.
For some reason, when ARRAY was added to the base it was never linked
to postgresql.ARRAY. Link the two types and also make base
ARRAY the schema event target so that it supports the same
features as postgresql.ARRAY.
Mike Bayer [Mon, 10 Apr 2017 17:25:50 +0000 (13:25 -0400)]
Compare entities also on chop_path
When comparing query._current_path to options, the path chop
was not taking into account that the query or the options are
against aliased classes that don't match the mapper.
The issue does not seem to take place for the Load() version
of _chop_path.
Fixed bug to improve upon the specificity of loader options that
take effect subsequent to the lazy load of a related entity, so
that the loader options will match to an aliased or non-aliased
entity more specifically if those options include entity information.
Mike Bayer [Mon, 3 Apr 2017 18:34:58 +0000 (14:34 -0400)]
Add new "expanding" feature to bindparam()
Added a new kind of :func:`.bindparam` called "expanding". This is
for use in ``IN`` expressions where the list of elements is rendered
into individual bound parameters at statement execution time, rather
than at statement compilation time. This allows both a single bound
parameter name to be linked to an IN expression of multiple elements,
as well as allows query caching to be used with IN expressions. The
new feature allows the related features of "select in" loading and
"polymorphic in" loading to make use of the baked query extension
to reduce call overhead. This feature should be considered to be
**experimental** for 1.2.
Mike Bayer [Wed, 5 Apr 2017 16:55:39 +0000 (12:55 -0400)]
Support Postgresql INTERVAL fields spec/reflection
Added support for all possible "fields" identifiers when reflecting the
Postgresql ``INTERVAL`` datatype, e.g. "YEAR", "MONTH", "DAY TO
MINUTE", etc.. In addition, the :class:`.postgresql.INTERVAL`
datatype itself now includes a new parameter
:paramref:`.postgresql.INTERVAL.fields` where these qualifiers can be
specified; the qualifier is also reflected back into the resulting
datatype upon reflection / inspection.
Mike Bayer [Mon, 4 Jul 2016 19:54:29 +0000 (15:54 -0400)]
Double percent signs based on paramstyle, not dialect
This patch moves the "doubling" of percent signs into
the base compiler and makes it completely a product
of whether or not the paramstyle is format/pyformat or
not. Without this paramstyle, percent signs
are not doubled across text(), literal_column(), and
column().