Commit Graph

450 Commits

Author SHA1 Message Date
Mike Bayer b37f007732 Default to using current mapped class as owner if none found
Repaired regression caused in 1.2.3 and 1.1.16 regarding association proxy
objects, revising the approach to 🎫`4185` when calculating the
"owning class" of an association proxy to default to choosing the current
class if the proxy object is not directly associated with a mapped class,
such as a mixin.

Change-Id: I87d0ac09f695dc285bd4bbe0a547f1d5ce23e068
Fixes: #4185
(cherry picked from commit 93881f7873048403b62cc3e179354712ba8e9282)
2018-02-20 16:42:24 -05:00
Mike Bayer cc6cef5184 Search through mapper superclass hierarchy for owner
Fixed regression caused by fix for issue 🎫`4116` affecting versions
1.2.2 as well as 1.1.15, which had the effect of mis-calculation of the
"owning class" of an :class:`.AssociationProxy` as the ``NoneType`` class
in some declarative mixin/inheritance situations as well as if the
association proxy were accessed off of an un-mapped class.  The "figure out
the owner" logic has been replaced by an in-depth routine that searches
through the complete mapper hierarchy assigned to the class or subclass to
determine the correct (we hope) match; will not assign the owner if no
match is found.  An exception is now raised if the proxy is used
against an un-mapped instance.

Change-Id: I611b590df2babe077ce6c19bea89e84251d1a7f4
Fixes: #4185
(cherry picked from commit 650b9eddae)
2018-02-09 16:31:24 -05:00
Mike Bayer 0be865d7bd Add tests for ARRAY propagate events re. MutableList
Issue #4141 appears in version 1.2, however we are adding the
MutableList test for it to 1.1 as well.  The metadata test
does not apply as in 1.1 ARRAY is not a SchemaEventTarget.

Change-Id: If8c57615860883837f6cf72661e46180a77778c1
(cherry picked from commit 14bb6eae364f41b6acbce782ebf5f984b9364af9)
2017-12-04 17:42:04 -05:00
Mike Bayer e06bf169e5 Filter attributes we don't map during a load_scalar_attributes
Fixed bug where a descriptor that is elsewhere a mapped column
or relationship within a hierarchy based on :class:`.AbstractConcreteBase`
would be referred towards during a refresh operation, causing an error
as the attribute is not mapped as a mapper property.
A similar issue can arise for other attributes like the "type" column
added by :class:`.AbstractConcreteBase` if the class fails to include
"concrete=True" in its mapper, however the check here should also
prevent that scenario from causing a problem.

Change-Id: I407b07a3a3e2c374da19fc86ed44b987d595dcfa
Fixes: #4124
(cherry picked from commit fd4289c582)
2017-10-28 13:30:18 -04:00
Mike Bayer e111940156 Resolve AliasedClass when determining owning class of association proxy
Fixed bug where the association proxy would inadvertently link itself
to an :class:`.AliasedClass` object if it were called first with
the :class:`.AliasedClass` as a parent, causing errors upon subsequent
usage.

Change-Id: I9161bab67766bb75d73ca54d712ad1cad6de40dc
Fixes: #4116
(cherry picked from commit f14a58dea4)
2017-10-23 20:36:18 -04:00
Mike Bayer 865d915d0e Remove unused .cascading from unit test for __table_cls__ feature
Two independent gerrits for 04bbad660b
and ec1700ba29 produce a failure
when merged due to new warning.
will merge into rel_1_1 as well for completeness even though
warning is not there.

Change-Id: I1bd494d205107d8b2a30d475a22c61a59b70985b
(cherry picked from commit 21ff71b0eb)
2017-09-28 13:07:45 -04:00
Mike Bayer d1ca3a8d46 Document and test __table_cls__
A use case has been identified for __table_cls__, which was
added in 1.0 just for the purpose of test fixtures.   Add this to
public API and ensure the target use case (conditional table generation)
stays supported.

Change-Id: I87be5bcb72205cab89871fa586663bf147450995
Fixes: #4082
(cherry picked from commit 04bbad660b)
2017-09-26 11:39:08 -04:00
Mike Bayer 1ad5ad165d Ensure we check that SQL expression has an .info attribute
Fixed regression released in 1.1.8 due to 🎫`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`.

Change-Id: I38254834d3d79c9b339289a8163eb4789ec4c931
Fixes: #3956
(cherry picked from commit d13734add3)
2017-04-04 09:07:14 -04:00
Mike Bayer 502a46b64e 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.

Change-Id: Ib04df862c58263185dbae686c548fea3e12c46f1
Fixes: #3950
(cherry picked from commit 07b63894cb)
2017-03-30 17:52:56 -04:00
Malaclypse The Younger 23585b842c 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.

Change-Id: I8c33548cf2a483699767e459731694c8cadebff6
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/350
(cherry picked from commit 74f6c21747)
2017-03-30 12:34:41 -04:00
Khairi Hafsham 772374735d Make all tests to be PEP8 compliant
tested using pycodestyle version 2.2.0

Fixes: #3885
Change-Id: I5df43adc3aefe318f9eeab72a078247a548ec566
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/343
2017-02-07 11:21:56 -05:00
Mike Bayer 9a5943bf76 Union the exclude_properties of the inheriting mapper in declarative
Fixed bug where the "automatic exclude" feature of declarative that
ensures a column local to a single table inheritance subclass does
not appear as an attribute on other derivations of the base would
not take effect for multiple levels of subclassing from the base.

Change-Id: Ibf67b631b4870dd1bd159f7d6085549d299fffe0
Fixes: #3895
2017-01-30 17:28:22 -05:00
mike bayer 5ef2fde8fb Merge "Add count(), scalar() to baked query" 2017-01-30 17:27:21 -05:00
Mike Bayer ecfda6512c Add count(), scalar() to baked query
Change-Id: I8af0d7b41ae2df384ce5d0ef274732352d81f376
Fixes: #3897
2017-01-30 13:02:29 -05:00
Jeong YunWon f411cac350 Fix nested index_property setter when there is no container value
Fixed bug in new :mod:`sqlalchemy.ext.indexable` extension
where setting of a property that itself refers to another property
would fail.

Fixes: #3901
Change-Id: I203a66117e2399afee11a34f43f0e93adfc6d571
2017-01-30 12:59:54 -05:00
Mike Bayer fa6dd376bb Support python3.6
Corrects some warnings and adds tox config.  Adds DeprecationWarning
to the error category.   Large sweep for string literals w/ backslashes
as this is common in docstrings

Co-authored-by: Andrii Soldatenko
Fixes: #3886
Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337
2017-01-13 10:57:41 -05:00
Mike Bayer ae7d2837b3 Assemble "don't joinedload other side" rule using query._current_path
Discovered during testing for [ticket:3822], the rule added
for [ticket:1495] will fail if the source object has propagated
options set up, which add elements to query._current_path.

Fixes: #3824
Change-Id: I3d96c96fee5f9b247f739d2136d18681ac61f2fe
2016-10-17 11:28:36 -04:00
Mike Bayer 95d4cd3042 Enhance "raise" strategy to include "raise_on_sql" option
The "raise_on_sql" option differentiates from "raise" in that
firing a lazy loader is OK as long as it does a simple
get from identity map.   Whereas "raise" is more useful
for the case that objects are to be detached.

As part of this, refactors the strategy initiation logic
a bit so that a LoaderStrategy itself knows what "key" was used
to create it, thus allowing variants of a single strategy
based on what the "lazy" argument is.  To achieve this we
have to also get rid of _get_strategy_by_cls().

Everything here is internal with the one exception of an apparently
undocumented, but not underscored, "strategy_class" key
on relationship().   Though it's not clear what
"strategy_class" accomplishes; at this point the strategy
system is extensible using Property.strategy_for().

Fixes: #3812
Change-Id: I812ad878ea5cf764e15f6f71cb39eee78a645d88
2016-10-04 12:09:29 -04:00
John Perkins e95aa257aa Add the "triggering mapper" to the configure_mappers error message.
There are cases where the originating mapper name is not
present in the exception message, such as relationship initialization
against an unmapped class.   Ensure the originating mapper is named
in the string output.

Pull-request: https://github.com/zzzeek/sqlalchemy/pull/298
Change-Id: I9f23bfa90b26dde9229ab7ec812eec9ceae48153
2016-09-20 12:11:11 -04:00
Mike Bayer 25804aeae2 Repair foreign_keys population for Join._refresh_for_new_column
Fixed bug where setting up a single-table inh subclass of a joined-table
subclass which included an extra column would corrupt the foreign keys
collection of the mapped table, thereby interfering with the
initialization of relationships.

Change-Id: I04a0cf98fd456d12d5a5b9e77a46a01246969a63
Fixes: #3797
2016-09-15 00:54:15 -04:00
Frazer McLean 87d5982e58 Add docstring to declarative_base
Change-Id: I5ad44362515908592f1e8b1e6254a5270d43234a
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/295
2016-08-06 02:25:27 +01:00
Mike Bayer 02190234a2 - a variety of test adjustments to accomodate for MySQL 5.7
Change-Id: Ied4245433d0d7b469dae6e7394c4931d8405f387
2016-07-24 16:36:27 -04:00
mike bayer 888f296540 Merge "Add default parameter for index_property" 2016-07-13 14:10:00 -04:00
Mark Hahnenberg bfa57063d4 Fix issue with unbaking subqueries
Fix improper capture of a loop variable inside a lambda during unbaking
of subquery eager loaders, which would cause the incorrect query
to be invoked.

Fixes: #3743
Change-Id: I995110deb8ee2dae8540486729e1ae64578d28fc
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/290
2016-07-12 14:09:14 -04:00
Jeong YunWon 21349b23dc Add default parameter for index_property
And force to use keyword arguments for trivial parameters in index_property

Change-Id: I12a178128182f77a2d06b52d7e36f59a36b45a33
2016-07-11 02:57:51 +09:00
Jeong YunWon 5a2d2f47d6 index_property catches IndexError as well as KeyError
It was raising AttributeError for key accessing in dict,
but raising IndexError for index accessing in array.

Change-Id: I58a2252a9e8d7f78cabcefcbe7223a4f3a729115
2016-07-05 18:24:47 -04:00
Mike Bayer acd8b1c107 Ensure @compiles calls down to the original compilation scheme
Made a slight behavioral change in the ``sqlalchemy.ext.compiler``
extension, whereby the existing compilation schemes for an established
construct would be removed if that construct was itself didn't already
have its own dedicated ``__visit_name__``.  This was a
rare occurrence in 1.0, however in 1.1 :class:`.postgresql.ARRAY`
subclasses :class:`.sqltypes.ARRAY` and has this behavior.
As a result, setting up a compilation handler for another dialect
such as SQLite would render the main :class:`.postgresql.ARRAY`
object no longer compilable.

Fixes: #3732
Change-Id: If2c1ada4eeb09157885888e41f529173902f2b49
2016-06-29 11:14:28 -04:00
Jeong YunWon 0620a76b58 Add sqlalchemy.ext.index for indexed attributes for ORM
Add `sqlalchemy.ext.index.index_property`
which subscribe an index of a column with `Indexable` type.

Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I238c23131e4fded5dc7f7a25eb02e26008099d00
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/235
2016-06-15 13:05:21 -04:00
Josh Marlow cafebe1604 Add schema argument to AutomapBase.prepare()
This allows automap to reflect tables from a schema other than the
default without the need to resort to calling MetaData.reflect
directly.

Change-Id: Ie73cb113bd6d115555c09c5efc33d27ad2c9c512
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/237
2016-06-02 14:00:13 -04:00
Mark Sandan ba3d4aa5ba change "psotgresql" to 'postgresql' in decorator 2016-05-06 18:26:31 -07:00
Mike Bayer 23825a2591 Deprecate Mapper.order_by
This is an old parameter no longer relevant to how SQLAlchemy
works, once the Query object was introduced.  By deprecating it
we establish that we aren't supporting non-working use cases
and that we encourage applications to move off of the use of this
parameter.

Fixes: #3394
Change-Id: I25b9a38142a1537bbcb27d3e8b66a8b265140072
2016-04-19 18:17:45 -04:00
Mike Bayer 6f6e2c48ba Propagate hybrid properties / info
Keystone and others depend on the .property attribute being
"mirrored" when a @hybrid_property is linked directly to a
mapped attribute.  Restore this linkage and also create a defined
behavior for the .info dictionary; it is that of the hybrid itself.
Add this behavioral change to the migration notes.

Change-Id: I8ac34ef52039387230c648866c5ca15d381f7fee
References: #3653
2016-04-18 16:20:20 -04:00
Mike Bayer 243b222a23 Honor hybrid property / method docstrings
The docstring specified on a hybrid property or method is now honored
at the class level, allowing it to work with tools like Sphinx
autodoc.  The mechanics here necessarily involve some wrapping of
expressions to occur for hybrid properties, which may cause them
to appear differently using introspection.

Fixes: #3653
Change-Id: I02549977fe8b2a051802eed7b00cc532fbc214e3
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/239
2016-04-18 12:55:48 -04:00
Jeong YunWon f7354b43e4 Add sqlalchemy.ext.mutable.MutableSet
from https://bitbucket.org/zzzeek/sqlalchemy/issues/3297
2016-02-13 21:28:50 +09:00
Jeong YunWon 1b6422a603 Add sqlalchemy.ext.mutable.MutableList 2016-02-13 21:28:46 +09:00
Mike Bayer 913858c949 - Further fixes to 🎫3605, pop method on :class:.MutableDict,
where the "default" argument was not included.
fixes #3605
2015-12-17 11:24:35 -05:00
Mike Bayer a22b208506 - Fixed bug in baked loader system where the systemwide monkeypatch
for setting up baked lazy loaders would interfere with other
loader strategies that rely on lazy loading as a fallback, e.g.
joined and subquery eager loaders, leading to ``IndexError``
exceptions at mapper configuration time.
fixes #3612
2015-12-15 21:44:00 -05:00
Mike Bayer 5710a1e88b - Added support for the `dict.pop() and dict.popitem()` methods
to the :class:`.mutable.MutableDict` class.
fixes #3605
2015-12-11 11:21:46 -05:00
Mike Bayer d5fd26b836 Merge remote-tracking branch 'origin/pr/212' 2015-11-30 12:46:45 -05:00
Mike Bayer 4fcd93afb8 - close the session 2015-11-29 21:50:50 -05:00
Mike Bayer b0308a7b3a - Fixed an issue in baked queries where the .get() method, used either
directly or within lazy loads, didn't consider the mapper's "get clause"
as part of the cache key, causing bound parameter mismatches if the
clause got re-generated.  This clause is cached by mappers
on the fly but in highly concurrent scenarios may be generated more
than once when first accessed.
fixes #3597
2015-11-29 11:42:55 -05:00
Nils Philippsen 58f73d2278 py2k: accept unicode literals on :func:backref, too
Fixed bug where in Py2K a unicode literal would not be accepted as the
string name of a class or other argument within declarative using
:func:`.backref` on :func:`.relationship`.

amends commit e6f67f4805
2015-11-25 16:03:59 +01:00
Mike Bayer c7f9aa2818 - rewrite the docs and add a test for the bake_queries=True
relationship flag; this flag *does* have an effect when the baked
lazy loader plugin has been invoked.  clarify the intent of this
flag as an "opt out" but only has an effect when the baked system
is loaded anyway.  fixes #3572
2015-11-19 14:23:08 -05:00
Mike Bayer 322f8f18f5 - exclude this from unpredictable gc 2015-10-11 12:44:29 -04:00
Mike Bayer 9d08c6abc2 - Added the :paramref:.AssociationProxy.info parameter to the
:class:`.AssociationProxy` constructor, to suit the
:attr:`.AssociationProxy.info` accessor that was added in
🎫`2971`.  This is possible because :class:`.AssociationProxy`
is constructed explicitly, unlike a hybrid which is constructed
implicitly via the decorator syntax.
fixes #3551
2015-10-09 18:01:43 -04:00
Mike Bayer 78a7bbdb3b Merge remote-tracking branch 'origin/pr/203' 2015-10-09 17:11:56 -04:00
Mike Bayer 414af7b612 - The system by which a :class:.Column considers itself to be an
"auto increment" column has been changed, such that autoincrement
is no longer implicitly enabled for a :class:`.Table` that has a
composite primary key.  In order to accommodate being able to enable
autoincrement for a composite PK member column while at the same time
maintaining SQLAlchemy's long standing behavior of enabling
implicit autoincrement for a single integer primary key, a third
state has been added to the :paramref:`.Column.autoincrement` parameter
``"auto"``, which is now the default. fixes #3216
- The MySQL dialect no longer generates an extra "KEY" directive when
generating CREATE TABLE DDL for a table using InnoDB with a
composite primary key with AUTO_INCREMENT on a column that isn't the
first column;  to overcome InnoDB's limitation here, the PRIMARY KEY
constraint is now generated with the AUTO_INCREMENT column placed
first in the list of columns.
2015-10-07 10:02:45 -04:00
Eric Siegerman 2e5e6ff96c Remplement Query.one() in terms of .one_or_none()
Thanks to Mike Bayer for suggesting a simpler refactoring.
2015-09-28 12:08:19 -04:00
Eric Siegerman 91255618dd Fix sqlalchemy.ext.baked.Result.one_or_none() exception message
Also add a couple of missing tests.
2015-09-24 15:25:15 -04:00
Mike Bayer 5b71858533 - replicate Query.one_or_none to BakedQuery
- changelog / version note finishing
2015-09-24 13:52:25 -04:00