summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/collections.py
Commit message (Collapse)AuthorAgeFilesLines
* Replace all http:// links to https://Federico Caselli2021-07-041-1/+1
| | | | | | Also replace http://pypi.python.org/pypi with https://pypi.org/project Change-Id: I84b5005c39969a82140706472989f2a30b0c7685
* Create new event for collection add w/o mutationMike Bayer2021-05-121-1/+51
| | | | | | | | | | | | | | | | Fixed issue when using :paramref:`_orm.relationship.cascade_backrefs` parameter set to ``False``, which per :ref:`change_5150` is set to become the standard behavior in SQLAlchemy 2.0, where adding the item to a collection that uniquifies, such as ``set`` or ``dict`` would fail to fire a cascade event if the object were already associated in that collection via the backref. This fix represents a fundamental change in the collection mechanics by introducing a new event state which can fire off for a collection mutation even if there is no net change on the collection; the action is now suited using a new event hook :meth:`_orm.AttributeEvents.append_wo_mutation`. Fixes: #6471 Change-Id: Ic50413f7e62440dad33ab84838098ea62ff4e815
* happy new yearMike Bayer2021-01-041-1/+1
| | | | Change-Id: Ic5bb19ca8be3cb47c95a0d3315d84cb484bac47c
* Document caveat about backrefs and attribute_mapped_collectionMike Bayer2020-08-261-4/+7
| | | | | Fixes: #5538 Change-Id: I2bda6bed40d35560a71bf0ed09d141047ce59e82
* Remove code deprecated before version 1.1Federico Caselli2020-04-091-32/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Remove deprecated method ``get_primary_keys` in the :class:`.Dialect` and :class:`.Inspector` classes. - Remove deprecated event ``dbapi_error`` and the method ``ConnectionEvents.dbapi_error`. - Remove support for deprecated engine URLs of the form ``postgres://``. - Remove deprecated dialect ``mysql+gaerdbms``. - Remove deprecated parameter ``quoting`` from :class:`.mysql.ENUM` and :class:`.mysql.SET` in the ``mysql`` dialect. - Remove deprecated function ``comparable_property``. and function ``comparable_using`` in the declarative extension. - Remove deprecated function ``compile_mappers``. - Remove deprecated method ``collection.linker``. - Remove deprecated method ``Session.prune`` and parameter ``Session.weak_identity_map``. This change also removes the class ``StrongInstanceDict``. - Remove deprecated parameter ``mapper.order_by``. - Remove deprecated parameter ``Session._enable_transaction_accounting`. - Remove deprecated parameter ``Session.is_modified.passive``. - Remove deprecated class ``Binary``. Please use :class:`.LargeBinary`. - Remove deprecated methods ``Compiled.compile``, ``ClauseElement.__and__`` and ``ClauseElement.__or__`` and attribute ``Over.func``. - Remove deprecated ``FromClause.count`` method. - Remove deprecated parameter ``Table.useexisting``. - Remove deprecated parameters ``text.bindparams`` and ``text.typemap``. - Remove boolean support for the ``passive`` parameter in ``get_history``. - Remove deprecated ``adapt_operator`` in ``UserDefinedType.Comparator``. Fixes: #4643 Change-Id: Idcd390c77bf7b0e9957907716993bdaa3f1a1763
* happy new yearMike Bayer2020-01-011-1/+1
| | | | Change-Id: I08440dc25e40ea1ccea1778f6ee9e28a00808235
* Skip on slice assignment to selfMike Bayer2019-11-201-0/+2
| | | | | | | | | | | | | 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. Fixes: #4990 Change-Id: I08727880f70f4fe188de53a4dcd36746b62c7233
* Remove unnecessary util.callable usageSteven Loria2019-09-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix typosMin ho Kim2019-07-211-1/+1
|
* Hold implicitly created collections in a pending areaMike Bayer2019-05-271-0/+45
| | | | | | | | | | | | | | | Accessing a collection-oriented attribute on a newly created object no longer mutates ``__dict__``, but still returns an empty collection as has always been the case. This allows collection-oriented attributes to work consistently in comparison to scalar attributes which return ``None``, but also don't mutate ``__dict__``. In order to accommodate for the collection being mutated, the same empty collection is returned each time once initially created, and when it is mutated (e.g. an item appended, added, etc.) it is then moved into ``__dict__``. This removes the last of mutating side-effects on read-only attribute access within the ORM. Fixes: #4519 Change-Id: I06a058d24e6eb24b5c6b6092d3f8b31cf9c244ae
* Implement new ClauseElement role and coercion systemMike Bayer2019-05-181-2/+3
| | | | | | | | | | | | | | | | | | | | A major refactoring of all the functions handle all detection of Core argument types as well as perform coercions into a new class hierarchy based on "roles", each of which identify a syntactical location within a SQL statement. In contrast to the ClauseElement hierarchy that identifies "what" each object is syntactically, the SQLRole hierarchy identifies the "where does it go" of each object syntactically. From this we define a consistent type checking and coercion system that establishes well defined behviors. This is a breakout of the patch that is reorganizing select() constructs to no longer be in the FromClause hierarchy. Also includes a rename of as_scalar() into scalar_subquery(); deprecates automatic coercion to scalar_subquery(). Partially-fixes: #4617 Change-Id: I26f1e78898693c6b99ef7ea2f4e7dfd0e8e1a1bd
* Add deprecation warnings to all deprecated APIsMike Bayer2019-01-231-1/+1
| | | | | | | | | | | | | | | A large change throughout the library has ensured that all objects, parameters, and behaviors which have been noted as deprecated or legacy now emit ``DeprecationWarning`` warnings when invoked. As the Python 3 interpreter now defaults to displaying deprecation warnings, as well as that modern test suites based on tools like tox and pytest tend to display deprecation warnings, this change should make it easier to note what API features are obsolete. See the notes added to the changelog and migration notes for further details. Fixes: #4393 Change-Id: If0ea11a1fc24f9a8029352eeadfc49a7a54c0a1b
* move to inspect_getfullargspecMike Bayer2019-01-151-4/+6
| | | | | | | | Replace inspect_getargspec with inspect_getfullargspec including a compatibility fallback for Py2k and use getfullargspec fully. Change-Id: I92bce0aafc37ce1a360b4f61b75f5892d0911c7e
* Merge "use ..deprecated directive w/ version in all cases"mike bayer2019-01-121-5/+20
|\
| * use ..deprecated directive w/ version in all casesMike Bayer2019-01-111-5/+20
| | | | | | | | | | | | | | | | | | These changes should be ported from 1.3 back to 1.0 or possibly 0.9 to the extent they are relevant in each version. In 1.3 we hope to turn all deprecation documentation into warnings. Change-Id: I205186cde161af9389af513a425c62ce90dd54d8
* | happy new yearMike Bayer2019-01-111-1/+1
|/ | | | Change-Id: I6a71f4924d046cf306961c58dffccf21e9c03911
* Post black reformattingMike Bayer2019-01-061-4/+4
| | | | | | | | | | | | | 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-109/+185
| | | | | | | | | | | | | | 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
* Call __del() before remove()Mike Bayer2018-12-281-13/+28
| | | | | | | | | | | | | | | | | | The "remove" event for collections is now called before the item is removed in the case of the ``collection.remove()`` method, as is consistent with the behavior for most other forms of collection item removal (such as ``__delitem__``, replacement under ``__setitem__``). The ``pop()`` methods are now the only exception as the target item is not available until after the pop operation proceeds. This allows ``remove()`` to be consistent in its behavior with all the other collection operations, allows the "before_delete" hook to be local to "pop()" operations only, and removes some method overhead. We are also looking here to gain some more predictability in terms of the fix for #1103. Change-Id: I4fdea911517d65cc300fae0e9c351a471e52e4ab
* Remove MappedCollection converter; deprecate @converterMike Bayer2018-09-271-24/+1
| | | | | | | | | | | | | | | | | | | Removed the collection converter used by the :class:`.MappedCollection` class. This converter was used only to assert that the incoming dictionary keys matched that of their corresponding objects, and only during a bulk set operation. The converter can interfere with a custom validator or :meth:`.AttributeEvents.bulk_replace` listener that wants to convert incoming values further. The ``TypeError`` which would be raised by this converter when an incoming key didn't match the value is removed; incoming values during a bulk assignment will be keyed to their value-generated key, and not the key that's explicitly present in the dictionary. Overall, @converter is superseded by the :meth:`.AttributeEvents.bulk_replace` event handler added as part of :ticket:`3896`. Fixes: #3604 Change-Id: Id0f7bd2cec938f5975eb2ab94df9ba5754dd43c3
* happy new yearMike Bayer2018-01-121-1/+1
| | | | Change-Id: I3ef36bfd0cb0ba62b3123c8cf92370a43156cf8f
* Add bulk_replace event, integrate with @validatesMike Bayer2017-03-161-3/+3
| | | | | | | | | | | | | | | | | | | | 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. Change-Id: I27f59db008d9e521d31a3e30143d7cd997e4b7b3 Fixes: #3896
* Don't mutate old collection on bulk replaceMike Bayer2017-03-151-2/+1
| | | | | | | | | | | | 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. Change-Id: Ic2685c85438191f07797d9ef97833a2cfdc4fcc2 Fixes: #3913
* update for 2017 copyrightMike Bayer2017-01-041-1/+1
| | | | Change-Id: I4e8c2aa8fe817bb2af8707410fa0201f938781de
* Add missing items to collection.__getstate__Mike Bayer2016-11-141-1/+7
| | | | | | | | | | the refactor in b606e47ddc54 / ticket:3457 failed to adjust __getstate__ / __setstate__. need to memoize a few more things including the class itself so that we can navigate back to "attr". Change-Id: I4ece2a616cb8b9dac7b50763ca59e47d0f26cfdf Fixes: #3852
* - happy new yearMike Bayer2016-01-291-1/+1
|
* - refactor of adapt_like_to_iterable(), fixes #3457.Mike Bayer2015-12-091-53/+19
| | | | | | Includes removal of adapt_like_to_iterable() as well as _set_iterable(), uses __slots__ for collectionadapter, does much less duck typing of collections.
* Update usages of getargspec to compat version.pr/210Jacob MacDonald2015-10-291-1/+2
| | | | | The places inspect.getargspec was being used were causing problems for newer Python versions.
* - copyright 2015Mike Bayer2015-03-101-1/+1
|
* minor docstring fix in MappedCollection classJochem Oosterveen2015-03-061-2/+2
|
* - cyclomatic complexity: instrument_class goes from E to an AMike Bayer2014-09-271-11/+37
|
* - Fixed bug in ordering list where the order of items would beMike Bayer2014-09-101-0/+10
| | | | | | | | thrown off during a collection replace event, if the reorder_on_append flag were set to True. The fix ensures that the ordering list only impacts the list that is explicitly associated with the object. fixes #3191
* - Added new event handlers :meth:`.AttributeEvents.init_collection`Mike Bayer2014-09-071-17/+6
| | | | | | | and :meth:`.AttributeEvents.dispose_collection`, which track when a collection is first associated with an instance and when it is replaced. These handlers supersede the :meth:`.collection.linker` annotation. The old hook remains supported through an event adapter.
* - apply pep8 formatting to sqlalchemy/sql, sqlalchemy/util, sqlalchemy/dialects,Brian Jarrett2014-07-201-35/+38
| | | | sqlalchemy/orm, sqlalchemy/event, sqlalchemy/testing
* - break up the <authors> copyright comment as part of a passMike Bayer2014-07-091-1/+2
| | | | to get all flake8 passing
* Documentation fix-up: "its" vs. "it's"pr/91Matthias Urlichs2014-05-111-1/+1
| | | | | | | | | Removed ungrammatical apostrophes from documentation, replacing "it's" with "its" where appropriate (but in a few cases with "it is" when that read better). While doing that, I also fixed a couple of minor typos etc. as I noticed them.
* - happy new yearMike Bayer2014-01-051-1/+1
|
* - changelogMike Bayer2013-11-301-7/+8
| | | | - put list.clear() instrumentation under "if not py2k"
* orm.collection, list.clear(). remove 'before_delete()', added unit-test.pr/40schettino722013-11-251-1/+0
|
* Add support for python3.3 list.clear() on orm.collectionsschettino722013-11-061-0/+9
|
* Fixed bug where list instrumentation would fail to represent aMike Bayer2013-08-201-1/+4
| | | | | | | | setslice of ``[0:0]`` correctly, which in particular could occur when using ``insert(0, item)`` with the association proxy. Due to some quirk in Python collections, the issue was much more likely with Python 3 rather than 2. Also in 0.8.3, 0.7.11. [ticket:2807]
* - apply an import refactoring to the ORM as wellMike Bayer2013-08-141-6/+5
| | | | | | | | | - rework the event system so that event modules load after their targets, dependencies are reversed - create an improved strategy lookup system for the ORM - rework the ORM to have very few import cycles - move out "importlater" to just util.dependency - other tricks to cross-populate modules in as clear a way as possible
* - after discussions with the original project folks working with zope securityMike Bayer2013-08-021-68/+55
| | | | | | | | | | | proxies, they aren't overriding getattr() or setattr() at all. so all the hardcoded getattr()/setattr() is removed from collections.py. Lots of these getattr/setattr were against the attributeimpl and decorated functions and don't seem like they'd ever be needed; for a user that needs special access to a collection, we can evaulate that use case and add a single point of "unwrapping", and probably add a hook for it via InstrumentationManager so that the collection implementation isn't complicated by it.
* a pass where we try to squash down as many list()/keys() combinationsMike Bayer2013-05-261-6/+6
| | | | as possible
* most of ORM passing...Mike Bayer2013-05-041-32/+25
|
* import of "sqlalchemy" and "sqlalchemy.orm" works.Mike Bayer2013-04-271-5/+1
|
* - the raw 2to3 runMike Bayer2013-04-271-38/+41
| | | | - went through examples/ and cleaned out excess list() calls
* Fixed the (most likely never used) "@collection.link" collectionMike Bayer2013-01-211-10/+13
|\ | | | | | | | | | | | | | | | | method, which fires off each time the collection is associated or de-associated with a mapped object - the decorator was not tested or functional. The decorator method is now named :meth:`.collection.linker` though the name "link" remains for backwards compatibility. Courtesy Luca Wehrstedt. [ticket:2653]
| * Fix the collection.link decoratorLuca Wehrstedt2013-01-161-9/+9
| |
* | - Made some fixes to the system of producing custom instrumentedMike Bayer2013-01-211-131/+88
|/ | | | | | | | | | | | | | | | | collections, mainly that the usage of the @collection decorators will now honor the __mro__ of the given class, applying the logic of the sub-most classes' version of a particular collection method. Previously, it wasn't predictable when subclassing an existing instrumented class such as :class:`.MappedCollection` whether or not custom methods would resolve correctly. [ticket:2654] - The undocumented (and hopefully unused) system of producing custom collections using an ``__instrumentation__`` datastructure associated with the collection has been removed, as this was a complex and untested feature which was also essentially redundant versus the decorator approach. Other internal simplifcations to the orm.collections module have been made as well.