summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/associationproxy.py
Commit message (Collapse)AuthorAgeFilesLines
* happy new yearMike Bayer2021-01-041-1/+1
| | | | Change-Id: Ic5bb19ca8be3cb47c95a0d3315d84cb484bac47c
* upgrade to black 20.8b1Mike Bayer2020-09-281-2/+1
| | | | | | | It's better, the majority of these changes look more readable to me. also found some docstrings that had formatting / quoting issues. Change-Id: I582a45fde3a5648b2f36bab96bad56881321899b
* Raise NotImplemenedError for association proxy __clause_element__Mike Bayer2020-08-271-0/+6
| | | | | | | | | It's not possible right now to use an association proxy element as a plain column expression to be SELECTed from or used in a SQL function. An informative error is now raised when this occurs. Fixes: #5542 Change-Id: I334e767ebc0b56c1dccc4a1e5185b0435af77b93
* Fix a wide variety of typos and broken linksaplatkouski2020-06-251-2/+2
| | | | | | | | | | | | Note the PR has a few remaining doc linking issues listed in the comment that must be addressed separately. Signed-off-by: aplatkouski <5857672+aplatkouski@users.noreply.github.com> Closes: #5371 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5371 Pull-request-sha: 7e7d233cf3a0c66980c27db0fcdb3c7d93bc2510 Change-Id: I9c36e8d8804483950db4b42c38ee456e384c59e3
* Run search and replace of symbolic module namesMike Bayer2020-04-141-3/+3
| | | | | | | | Replaces a wide array of Sphinx-relative doc references with an abbreviated absolute form now supported by zzzeeksphinx. Change-Id: I94bffcc3f37885ffdde6238767224296339698a2
* Enable zzzeeksphinx module prefixesMike Bayer2020-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | zzzeeksphinx 1.1.2 in git can now convert short prefix names in a configured lookup to fully qualified module names, so that we can have succinct and portable pyrefs that still resolve absolutely. It also includes a formatter that will format all pyrefs in a fully consistent way regardless of the package path, by unconditionally removing all package tokens but always leaving class names in place including for methods, which means we no longer have to deal with tildes in pyrefs. The most immediate goal of the absolute prefixes is that we have lots of "ambiguous" names that appear in muliple places, like select(), ARRAY, ENUM etc. With the incoming future packages there is going to be lots of name overlap so it is necessary that all names eventually use absolute package paths when Sphinx receives them. In multiple stages, pyrefs will be converted using the zzzeeksphinx tools/fix_xrefs.py tool so that doclinks can be made absolute using symbolic prefixes. For this review, the actual search and replace of symbols is not performed, instead some general cleanup to prepare the docs as well as a lookup file used by the tool to do the conversion. this relatively small patch will be backported with appropriate changes to 1.3, 1.2, 1.1 and the tool can then be run on each branch individually. We are shooting for almost no warnings at all for master (still a handful I can't figure out which don't seem to have any impact) , very few for 1.3, and for 1.2 / 1.1 we hope for a significant reduction in warnings. Overall for all versions pyrefs should always point to the correct target, if they are in fact hyperlinked. it's better for a ref to go nowhere and be plain text than go to the wrong thing. Right now, hundreds of API links are pointing to the wrong thing as they are ambiguous names such as refresh(), insert(), update(), select(), join(), JSON etc. and Sphinx sends these all to essesntially random destinations among as many as five or six possible choices per symbol. A shorthand system that allows us to use absolute refs without having to type out a full blown absoulte module is the only way this is going to work, and we should ultimately seek to abandon any use of prefix dot for lookups. Everything should be on an underscore token so at the very least the module spaces can be reorganized without having to search and replace the entire documentation every time. Change-Id: I484a7329034af275fcdb322b62b6255dfeea9151
* Ensure all nested exception throws have a causeMike Bayer2020-03-021-7/+17
| | | | | | | | | | | | | | | Applied an explicit "cause" to most if not all internally raised exceptions that are raised from within an internal exception catch, to avoid misleading stacktraces that suggest an error within the handling of an exception. While it would be preferable to suppress the internally caught exception in the way that the ``__suppress_context__`` attribute would, there does not as yet seem to be a way to do this without suppressing an enclosing user constructed context, so for now it exposes the internally caught exception as the cause so that full information about the context of the error is maintained. Fixes: #4849 Change-Id: I55a86b29023675d9e5e49bc7edc5a2dc0bcd4751
* happy new yearMike Bayer2020-01-011-1/+1
| | | | Change-Id: I08440dc25e40ea1ccea1778f6ee9e28a00808235
* Remove unnecessary util.callable usageSteven Loria2019-09-091-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes: #4850 <!-- Provide a general summary of your proposed changes in the Title field above --> ### Description <!-- Describe your changes in detail --> Removes usage of `util.callable`. ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #4851 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4851 Pull-request-sha: a0ccdff2cb74f5e944d8baccc269c382b591c8e2 Change-Id: I79918f44becbc5dbefdc7ff65128695c1cabed1d
* Consult is_attrbute flag to determine descriptor; enable for assoc proxyMike Bayer2019-06-141-1/+1
| | | | | | | | | | | | Fixed bug where the :attr:`.Mapper.all_orm_descriptors` accessor would return an entry for the :class:`.Mapper` itself under the declarative ``__mapper___`` key, when this is not a descriptor. The ``.is_attribute`` flag that's present on all :class:`.InspectionAttr` objects is now consulted, which has also been modified to be ``True`` for an association proxy, as it was erroneously set to False for this object. Fixes: #4729 Change-Id: Ia02388cc25d004e32d337140b62a587f3e5a0b7b
* Add QueryableAttribute._impl_uses_objects accessor for AssociationProxyMike Bayer2019-05-191-6/+2
| | | | | | | | | | | | | | 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. Fixes: #4690 Change-Id: I5b5300661291c94a23de53bcf92d747701720aa1
* Resolve RST306 issuesMike Bayer2019-05-131-2/+2
| | | | | | | | The latest flake8 seems to look for these and they are in fact correctable with a backslash. Also need to add r to the strings to avoid W605. Change-Id: I8045309aa2ad29978ba7e99c45f75bc1457dff3d
* remote_attr and local_attr refer to class bound attributes, notMike Bayer2019-04-251-2/+2
| | | | | | MapperProperty Change-Id: If5fee69474f295e8c4bef891f5360f6b54080bbf
* - formatting typoMike Bayer2019-04-251-1/+1
| | | | Change-Id: Ia34c2f9a6c3db83bbe0f0a06f82aa04c603cb521
* Refine ambiguous access for unknown attribute typesMike Bayer2019-03-261-2/+21
| | | | | | | | | | | | | | | | Restored instance-level support for plain Python descriptors, e.g. ``@property`` objects, in conjunction with association proxies, in that if the proxied object is not within ORM scope at all, it gets classified as "ambiguous" but is proxed directly. For class level access, a basic class level``__get__()`` now returns the :class:`.AmbiguousAssociationProxyInstance` directly, rather than raising its exception, which is the closest approximation to the previous behavior that returned the :class:`.AssociationProxy` itself that's possible. Also improved the stringification of these objects to be more descriptive of current state. Fixes: #4574 Change-Id: I787a22806b5530c146ae6ee66b588e5b191ae689
* Add documentation section for cascade_scalar_deletesMike Bayer2019-03-071-0/+4
| | | | | Change-Id: I56825652e0608862472bc594fc6c2b12ed5cc16f References: #4534
* Add bulk_replace to AssociationSet, AssociationDictMike Bayer2019-02-041-2/+38
| | | | | | | | | | | Implemented a more comprehensive assignment operation (e.g. "bulk replace") when using association proxy with sets or dictionaries. Fixes the problem of redundant proxy objects being created to replace the old ones, which leads to excessive events and SQL and in the case of unique constraints will cause the flush to fail. Fixes: #2642 Change-Id: I57ab27dd9feba057e539267722cce92254fca777
* Fix many spell glitchesLele Gaifax2019-01-251-1/+1
| | | | | | | | | | | | This affects mostly docstrings, except in orm/events.py::dispose_collection() where one parameter gets renamed: given that the method is empty, it seemed reasonable to me to fix that too. Closes: #4440 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4440 Pull-request-sha: 779ed75acb6142e1f1daac467b5b14134529bb4b Change-Id: Ic0553fe97853054b09c2453af76d96363de6eb0e
* Relax "ambiguous" association proxy restrictions, support ProxyMike Bayer2019-01-141-17/+25
| | | | | | | | | | | | Fixed issue in association proxy due to :ticket:`3423` which caused the use of custom :class:`.PropComparator` objects with hybrid attribites, such as the one demonstrated in the ``dictlike-polymorphic`` example to not function within an association proxy. The strictness that was added in :ticket:`3423` has been relaxed, and additional logic to accomodate for an association proxy that links to a custom hybrid have been added. Fixes: #4446 Change-Id: I8addc80f51094769915ac2dce1a301bd72ee7433
* happy new yearMike Bayer2019-01-111-1/+1
| | | | Change-Id: I6a71f4924d046cf306961c58dffccf21e9c03911
* Post black reformattingMike Bayer2019-01-061-17/+21
| | | | | | | | | | | | | Applied on top of a pure run of black -l 79 in I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9, this set of changes resolves all remaining flake8 conditions for those codes we have enabled in setup.cfg. Included are resolutions for all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
* Run black -l 79 against all source filesMike Bayer2019-01-061-99/+189
| | | | | | | | | | | | | | This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
* Take instance into account when determining AssociationProxyInstanceMike Bayer2018-12-071-17/+136
| | | | | | | | | | Fixed a regression in 1.3.0b1 caused by :ticket:`3423` where association proxy objects that access an attribute that's only present on a polymorphic subclass would raise an ``AttributeError`` even though the actual instance being accessed was an instance of that subclass. Fixes: #4401 Change-Id: Ie62c48aa9142adff45cbf9a297184987c72f30f3
* Add missing index method to _AssociationList.Chris Macklin2018-10-311-0/+3
| | | | | | | | Added missing ``.index()`` method to list-based association collections in the association proxy extension. Change-Id: Ice81dc4bcccd520638c5bc9a0f8bb2027946c846 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/485
* Create object- and column-oriented versions of AssociationProxyInstanceMike Bayer2018-10-261-19/+81
| | | | | | | | | | | | | | The :class:`.AssociationProxy` now has standard column comparison operations such as :meth:`.ColumnOperators.like` and :meth:`.ColumnOperators.startswith` available when the target attribute is a plain column - the EXISTS expression that joins to the target table is rendered as usual, but the column expression is then use within the WHERE criteria of the EXISTS. Note that this alters the behavior of the ``.contains()`` method on the association proxy to make use of :meth:`.ColumnOperators.contains` when used on a column-based attribute. Fixes: #4351 Change-Id: I310941f4e8f778c200f8144a26a89e5364cd4dfb
* Strong reference parent object in association proxyMike Bayer2018-10-011-10/+4
| | | | | | | | | | | | | | | | Considering the reversal of #597 as well as 84420a1d0fe09d7a45e878e853aa9f5258561f8b as I am unable to reproduce the original issues from that release. The long-standing behavior of the association proxy collection maintaining only a weak reference to the parent object is reverted; the proxy will now maintain a strong reference to the parent for as long as the proxy collection itself is also in memory, eliminating the "stale association proxy" error. This change is being made on an experimental basis to see if any use cases arise where it causes side effects. Change-Id: I051334be90a343dd0e8a1f35e072075eb14b14a7 Fixes: #4268
* Break association proxy into a descriptor + per-class accessorMike Bayer2018-09-271-133/+220
| | | | | | | | | | | | Reworked :class:`.AssociationProxy` to store state that's specific to a parent class in a separate object, so that a single :class:`.AssocationProxy` can serve for multiple parent classes, as is intrinsic to inheritance, without any ambiguity in the state returned by it. A new method :meth:`.AssociationProxy.for_class` is added to allow inspection of class-specific state. Change-Id: I634f88aae6306ac5c5237a0e1acbe07d0481d6b6 Fixes: #3423
* Handle association proxy delete and provide for scalar delete cascadeMike Bayer2018-08-011-2/+21
| | | | | | | | | | | Fixed multiple issues regarding de-association of scalar objects with the association proxy. ``del`` now works, and additionally a new flag :paramref:`.AssociationProxy.cascade_scalar_deletes` is added, which when set to True indicates that setting a scalar attribute to ``None`` or deleting via ``del`` will also set the source association to ``None``. Change-Id: I1580d761571d63eb03a7e8df078cef97d265b85c Fixes: #4308
* Do some pep8 and other cruft removal around association proxyMike Bayer2018-08-011-11/+13
| | | | Change-Id: I33130022a7e223318b65388620828d539f6dacfd
* Default to using current mapped class as owner if none foundMike Bayer2018-02-201-1/+6
| | | | | | | | | | | Repaired regression caused in 1.2.3 and 1.1.16 regarding association proxy objects, revising the approach to :ticket:`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
* Search through mapper superclass hierarchy for ownerMike Bayer2018-02-091-13/+35
| | | | | | | | | | | | | | | | Fixed regression caused by fix for issue :ticket:`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
* happy new yearMike Bayer2018-01-121-1/+1
| | | | Change-Id: I3ef36bfd0cb0ba62b3123c8cf92370a43156cf8f
* Check for the endmost target when chaining contains()Mike Bayer2018-01-021-0/+1
| | | | | | | | | | | | Fixed regression in association proxy due to :ticket:`3769` (allow for chained any() / has()) where contains() against an association proxy chained in the form (o2m relationship, associationproxy(m2o relationship, m2o relationship)) would raise an error regarding the re-application of contains() on the final link of the chain. Change-Id: Iea51ce84c2c5a332416fff10b1ba0e676cf0bad7 Fixes: #4150
* Resolve AliasedClass when determining owning class of association proxyMike Bayer2017-10-201-1/+12
| | | | | | | | | | 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
* Support AssociationProxy any() / has() / contains() to another AssociationProxyMike Bayer2017-06-121-36/+68
| | | | | | | | | | | | | | | | | | | The :meth:`.AssociationProxy.any`, :meth:`.AssociationProxy.has` and :meth:`.AssociationProxy.contains` comparison methods now support linkage to an attribute that is itself also an :class:`.AssociationProxy`, recursively. After some initial attempts it's clear that the any() / has() of AssociationProxy needed to be reworked into a generic _criterion_exists() to allow this to work recursively without excess complexity. For the case of the multi-linked associationproxy, the usual checks of "any()" / "has()" correctness simply don't take place; for a single-link association proxy the error checking logic that takes place in relationship() has been ported to the local any() / has() methods. Change-Id: Ic5aed2a4e910b8138a737d215430113c31cce856 Fixes: #3769
* Call proxied collection before invoking creator in associationlist.append()Mike Bayer2017-04-281-1/+2
| | | | | | | | | | | | 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. Change-Id: I008a6dbdfe5b1c0dfd02189c3d954d83a65f3fc5 Fixes: #3941
* Support python3.6Mike Bayer2017-01-131-1/+1
| | | | | | | | | | | 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
* update for 2017 copyrightMike Bayer2017-01-041-1/+1
| | | | Change-Id: I4e8c2aa8fe817bb2af8707410fa0201f938781de
* - happy new yearMike Bayer2016-01-291-1/+1
|
* Change generator termination from StopIteration to return.pr/211pgjones2015-10-301-2/+2
| | | | | | | | | | | From [PEP 479](https://www.python.org/dev/peps/pep-0479/) the correct way to terminate a generator is to return (which implicitly raises StopIteration) rather than raise StopIteration. Without this change using sqlalchemy in python 3.5 or greater results in these warnings PendingDeprecationWarning: generator '__iter__' raised StopIteration which this commit should remove.
* - Added the :paramref:`.AssociationProxy.info` parameter to theMike Bayer2015-10-091-1/+8
| | | | | | | | | :class:`.AssociationProxy` constructor, to suit the :attr:`.AssociationProxy.info` accessor that was added in :ticket:`2971`. This is possible because :class:`.AssociationProxy` is constructed explicitly, unlike a hybrid which is constructed implicitly via the decorator syntax. fixes #3551
* - Fixed bug in association proxy where an any()/has()Mike Bayer2015-04-281-6/+10
| | | | | | | on an relationship->scalar non-object attribute comparison would fail, e.g. ``filter(Parent.some_collection_to_attribute.any(Child.attr == 'foo'))`` fixes #3397
* - copyright 2015Mike Bayer2015-03-101-1/+1
|
* Fix slice addressing of _AssociationList with python3Gilles Dartiguelongue2015-03-101-1/+4
|
* - add MemoizedSlots, a generalized solution to using __getattr__Mike Bayer2015-01-051-1/+1
| | | | | for memoization on a class that uses slots. - apply many more __slots__. mem use for nova now at 46% savings
* - rename _InspectionAttr to InspectionAttrMike Bayer2014-08-131-3/+3
|
* PEP8 style fixesBrian Jarrett2014-07-131-24/+24
|
* - break up the <authors> copyright comment as part of a passMike Bayer2014-07-091-1/+2
| | | | to get all flake8 passing
* - Fixed bug in association proxy where assigning an empty sliceMike Bayer2014-03-041-2/+3
| | | | (e.g. ``x[:] = [...]``) would fail on Py3k.
* - Fixed a regression in association proxy caused by :ticket:`2810` whichMike Bayer2014-02-271-5/+3
| | | | | | | | | caused a user-provided "getter" to no longer receive values of ``None`` when fetching scalar values from a target that is non-present. The check for None introduced by this change is now moved into the default getter, so a user-provided getter will also again receive values of None. re: #2810