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().
Mike Bayer [Mon, 3 Apr 2017 19:05:27 +0000 (15:05 -0400)]
Recognize brackets, quoted_name in SQL Server schema
The SQL Server dialect now allows for a database and/or owner name
with a dot inside of it, using brackets explicitly in the string around
the owner and optionally the database name as well. In addition,
sending the :class:`.quoted_name` construct for the schema name will
not split on the dot and will deliver the full string as the "owner".
:class:`.quoted_name` is also now available from the ``sqlalchemy.sql``
import space.
Mike Bayer [Tue, 4 Apr 2017 14:02:39 +0000 (10:02 -0400)]
Apply SQL compilation to sqltext for column-level CHECK constraint
Fixed bug where a column-level :class:`.CheckConstraint` would fail
to compile the SQL expression using the underlying dialect compiler
as well as apply proper flags to generate literal values as
inline, in the case that the sqltext is a Core expression and
not just a plain string. This was long-ago fixed for table-level
check constraints in 0.9 as part of :ticket:`2742`, which more commonly
feature Core SQL expressions as opposed to plain string expressions.
Mike Bayer [Tue, 4 Apr 2017 13:06:13 +0000 (09:06 -0400)]
Ensure we check that SQL expression has an .info attribute
Fixed regression released in 1.1.8 due to :ticket:`3950` where the
deeper search for information about column types in the case of a
"schema type" or a :class:`.TypeDecorator` would produce an attribute
error if the mapping also contained a :obj:`.column_property`.
Mike Bayer [Mon, 3 Apr 2017 21:25:26 +0000 (17:25 -0400)]
ResultProxy won't autoclose connection until state flag is set
Changed the mechanics of :class:`.ResultProxy` to unconditionally
delay the "autoclose" step until the :class:`.Connection` is done
with the object; in the case where Postgresql ON CONFLICT with
RETURNING returns no rows, autoclose was occurring in this previously
non-existent use case, causing the usual autocommit behavior that
occurs unconditionally upon INSERT/UPDATE/DELETE to fail.
Mike Bayer [Thu, 16 Mar 2017 21:28:41 +0000 (17:28 -0400)]
Use consistent method signature for Alias.self_group()
Fixed bug where the use of an :class:`.Alias` object in a column
context would raise an argument error when it tried to group itself
into a parenthesized expression. Using :class:`.Alias` in this way
is not yet a fully supported API, however it applies to some end-user
recipes and may have a more prominent role in support of some
future Postgresql features.
Mike Bayer [Sat, 1 Apr 2017 15:36:16 +0000 (11:36 -0400)]
Return self when Variant.coerce_compared_value would return impl
Fixed regression released in 1.1.5 due to :ticket:`3859` where
adjustments to the "right-hand-side" evaluation of an expression
based on :class:`.Variant` to honor the underlying type's
"right-hand-side" rules caused the :class:`.Variant` type
to be inappropriately lost, in those cases when we *do* want the
left-hand side type to be transferred directly to the right hand side
so that bind-level rules can be applied to the expression's argument.
Mike Bayer [Thu, 30 Mar 2017 21:52:10 +0000 (17:52 -0400)]
Track SchemaEventTarget types in as_mutable()
Fixed bug in :mod:`sqlalchemy.ext.mutable` where the
:meth:`.Mutable.as_mutable` method would not track a type that had
been copied using :meth:`.TypeEngine.copy`. This became more of
a regression in 1.1 compared to 1.0 because the :class:`.TypeDecorator`
class is now a subclass of :class:`.SchemaEventTarget`, which among
other things indicates to the parent :class:`.Column` that the type
should be copied when the :class:`.Column` is. These copies are
common when using declarative with mixins or abstract classes.
Mike Bayer [Mon, 27 Feb 2017 21:43:59 +0000 (16:43 -0500)]
Apply type processing to untyped preexec default clause
Fixed bug where a SQL-oriented Python-side column default could fail to
be executed properly upon INSERT in the "pre-execute" codepath, if the
SQL itself were an untyped expression, such as plain text. The "pre-
execute" codepath is fairly uncommon however can apply to non-integer
primary key columns with SQL defaults when RETURNING is not used.
Tests exist here to ensure typing is applied to
a typed expression for default, but in the case of
an untyped SQL value, we know the type from the column,
so apply this.
Add bindparams support for baked Result count() method
Added support for bound parameters, e.g. those normally set up
via :meth:`.Query.params`, to the :meth:`.baked.Result.count`
method. Previously, support for parameters were omitted. Pull request
courtesy Pat Deegan.
Mike Bayer [Mon, 27 Mar 2017 17:48:40 +0000 (13:48 -0400)]
Allow aliased() to be passed to Query.select_entity_from().
An :func:`.aliased()` construct can now be passed to the
:meth:`.Query.select_entity_from` method. Entities will be pulled
from the selectable represented by the :func:`.aliased` construct.
This allows special options for :func:`.aliased` such as
:paramref:`.aliased.adapt_on_names` to be used in conjunction with
:meth:`.Query.select_entity_from`.
Additionally rewrote the docstring for :meth:`.Query.select_entity_from`,
including starting with explicit use of :func:`.aliased` as the
usual idiomatic pattern. An example using text().columns() is added
as well as the use case from :ticket:`3933` using name matching.
Mike Bayer [Mon, 27 Mar 2017 14:52:58 +0000 (10:52 -0400)]
Add safe_reraise() + warnings only to Connection._autorollback
Added an exception handler that will warn for the "cause" exception on
Py2K when the "autorollback" feature of :class:`.Connection` itself
raises an exception. In Py3K, the two exceptions are naturally reported
by the interpreter as one occurring during the handling of the other.
This is continuing with the series of changes for rollback failure
handling that were last visited as part of :ticket:`2696` in 1.0.12.
Mike Bayer [Sun, 26 Mar 2017 02:17:17 +0000 (22:17 -0400)]
Pre-load alias.c within JoinedEagerLoader cached AliasedClass
Fixed a race condition which could occur under threaded environments
as a result of the caching added via :ticket:`3915`. An internal
collection of ``Column`` objects could be regenerated on an alias
object inappropriately, confusing a joined eager loader when it
attempts to render SQL and collect results and resulting in an
attribute error. The collection is now generated up front before
the alias object is cached and shared among threads.
Mike Bayer [Thu, 23 Mar 2017 19:11:03 +0000 (15:11 -0400)]
Treat collation names as identifiers
The expression used for COLLATE as rendered by the column-level
:func:`.expression.collate` and :meth:`.ColumnOperators.collate` is now
quoted as an identifier when the name is case sensitive, e.g. has
uppercase characters. Note that this does not impact type-level
collation, which is already quoted.
Mike Bayer [Wed, 22 Mar 2017 16:56:23 +0000 (12:56 -0400)]
Support hybrids/composites with bulk updates
The :meth:`.Query.update` method can now accommodate both
hybrid attributes as well as composite attributes as a source
of the key to be placed in the SET clause. For hybrids, an
additional decorator :meth:`.hybrid_property.update_expression`
is supplied for which the user supplies a tuple-returning function.
Mike Bayer [Wed, 22 Mar 2017 14:13:15 +0000 (10:13 -0400)]
Use config.db global opts as defaults for all testing_engine()
Some options need to be passed to engines in all cases,
such as currently the oracle 12516 workaround. make sure
calls to testing_engine also set up the dictionary with
defaults even if options is passed. not clear if this affects
other backends yet.
Mike Bayer [Tue, 21 Mar 2017 21:11:18 +0000 (17:11 -0400)]
Raise on flag_modified() for non-present attribute
The :func:`.attributes.flag_modified` function now raises
:class:`.InvalidRequestError` if the named attribute key is not
present within the object, as this is assumed to be present
in the flush process. To mark an object "dirty" for a flush
without referring to any specific attribute, the
:func:`.attributes.flag_dirty` function may be used.
Diana Clarke [Thu, 16 Mar 2017 20:05:18 +0000 (16:05 -0400)]
Allow reuse of hybrid_property across subclasses
The :class:`sqlalchemy.ext.hybrid.hybrid_property` class now supports
calling mutators like ``@setter``, ``@expression`` etc. multiple times
across subclasses, and now provides a ``@getter`` mutator, so that
a particular hybrid can be repurposed across subclasses or other
classes. This now matches the behavior of ``@property`` in standard
Python.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #3911 Fixes: #3912
Change-Id: Iff033d8ccaae20ded9289cbfa789c376759381f5
Mike Bayer [Fri, 24 Feb 2017 15:50:14 +0000 (10:50 -0500)]
Integrate "pre-ping" into connection pool.
Added native "pessimistic disconnection" handling to the :class:`.Pool`
object. The new parameter :paramref:`.Pool.pre_ping`, available from
the engine as :paramref:`.create_engine.pool_pre_ping`, applies an
efficient form of the "pre-ping" recipe featured in the pooling
documentation, which upon each connection check out, emits a simple
statement, typically "SELECT 1", to test the connection for liveness.
If the existing connection is no longer able to respond to commands,
the connection is transparently recycled, and all other connections
made prior to the current timestamp are invalidated.
Frazer McLean [Sat, 11 Jun 2016 19:47:33 +0000 (21:47 +0200)]
Implement comments for tables, columns
Added support for SQL comments on :class:`.Table` and :class:`.Column`
objects, via the new :paramref:`.Table.comment` and
:paramref:`.Column.comment` arguments. The comments are included
as part of DDL on table creation, either inline or via an appropriate
ALTER statement, and are also reflected back within table reflection,
as well as via the :class:`.Inspector`. Supported backends currently
include MySQL, Postgresql, and Oracle.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #1546
Change-Id: Ib90683850805a2b4ee198e420dc294f32f15d35d
Mike Bayer [Wed, 25 Jan 2017 16:51:04 +0000 (11:51 -0500)]
Add bulk_replace event, integrate with @validates
Added new attribute event :meth:`.AttributeEvents.bulk_replace`.
This event is triggered when a collection is assigned to a
relationship, before the incoming collection is compared with the
existing one. This early event allows for conversion of incoming
non-ORM objects as well. The event is integrated with the
``@validates`` decorator.
The ``@validates`` decorator now allows the decorated method to receive
objects from a "bulk collection set" operation that have not yet
been compared to the existing collection. This allows incoming values
to be converted to compatible ORM objects as is already allowed
from an "append" event. Note that this means that the
``@validates`` method is called for **all** values during a collection
assignment, rather than just the ones that are new.
Mike Bayer [Mon, 16 Jan 2017 18:34:55 +0000 (13:34 -0500)]
Annotate parentmapper in primaryjoin / secondaryjoin
This patch applies the "parentmapper" annotation to the columns
in the primaryjoin/secondaryjoin, but more dramatically,
also removes all the "deannotate" steps that were historically
applied to the relationship primaryjoin/secondaryjoin.
These deannotation steps were left over from the initial
implementations of annotations where the behaviors were not
as reliable.
By ensuring these annotations are present,
the evaluator no longer needs to do a name-based lookup
when it sees a column that has no "parentmapper",
because it can be assured this is not a mapped column.
This fixes the issue where the expression were based on
a relationship primaryjoin but the name of a column
in the join condition didn't match the attribute name.
Mike Bayer [Tue, 14 Feb 2017 16:39:44 +0000 (11:39 -0500)]
Don't mutate old collection on bulk replace
For a bulk replace, assume the old collection is no longer
useful to the attribute system and only send the removal events,
not actually mutated the collection.
this changes behavior significantly and also means that dispose_collection
now receives the old collection intact.
Mike Bayer [Wed, 15 Mar 2017 14:15:12 +0000 (10:15 -0400)]
Consult compiled paramstyle on execute_compiled
Fixed bug where in the unusual case of passing a
:class:`.Compiled` object directly to :meth:`.Connection.execute`,
the dialect with which the :class:`.Compiled` object were generated
was not consulted for the paramstyle of the string statement, instead
assuming it would match the dialect-level paramstyle, causing
mismatches to occur.
Mike Bayer [Mon, 16 Jan 2017 18:06:44 +0000 (13:06 -0500)]
Consult _select_from_entity in _adjust_for_single_inheritance
Fixed bug in single-table inheritance where the select_from()
argument would not be taken into account when limiting rows
to a subclass. Previously, only expressions in the
columns requested would be taken into account.
Mike Bayer [Tue, 14 Mar 2017 16:00:56 +0000 (12:00 -0400)]
Add "empty in" strategies; default to "static"
The longstanding behavior of the :meth:`.Operators.in_` and
:meth:`.Operators.not_in_` operators emitting a warning when
the right-hand condition is an empty sequence has been revised;
a new flag :paramref:`.create_engine.empty_in_strategy` allows an
empty "IN" expression to generate a simple boolean expression, or
to invoke the previous behavior of dis-equating the expression to
itself, with or without a warning. The default behavior is now
to emit the simple boolean expression, allowing an empty IN to
be evaulated without any performance penalty.
Mike Bayer [Thu, 9 Mar 2017 16:36:19 +0000 (11:36 -0500)]
Improve serializer behavior
Fix an issue where the Annotated system needs to have a
__reduce__ method, also see why we can't default to HIGHEST_PROTOCOL.
This latter part might not be a good idea until 1.2 for compatibility
reasons.
Mike Bayer [Sat, 11 Mar 2017 15:52:43 +0000 (10:52 -0500)]
Emit after_rollback() event before snapshot removal
The state of the :class:`.Session` is now present when the
:meth:`.SessionEvents.after_rollback` event is emitted, that is, the
attribute state of objects prior to their being expired. This is now
consistent with the behavior of the
:meth:`.SessionEvents.after_commit` event which also emits before the
attribute state of objects is expired.