summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm
Commit message (Collapse)AuthorAgeFilesLines
* Ensure .mapper is set on _ColumnEntityMike Bayer2016-10-211-1/+6
| | | | | | | | | | | | | | _ColumnEntity didn't seem to have .mapper present, which due to the way _mapper_zero() worked didn't tend to come across it. With :ticket:`3608` _mapper_zero() has been simplified so make sure this is now present. Also ensure that _select_from_entity is an entity and not a mapped class, though this does not seem to matter at the moment. Fixes: #3836 Change-Id: Id6dae8e700269b97de3b01562edee95ac1e01f80
* Rewrite migration notes for [ticket:3514]Mike Bayer2016-10-191-0/+6
| | | | | | | | | | | | | | | | | | | The change to "evaluates none" datatypes in the ORM was not fully described in the migration notes, missing the key behavioral change that a column which is missing a default entirely will not receive a value for a missing JSON column now. The issue here touched upon a revisit of the assumptions in [ticket:3514], but overall the old behavior "worked" mostly because the ORM wants to explicitly render NULL into an INSERT for column values that are missing, which itself is a legacy behavior which should be considered for possible removal in a future major release. Given that "missing ORM value + no column default set up == dont put it in the INSERT" would be the most intuitive behavior, the move in [ticket:3514] represents a step in this direction. Change-Id: I454d5bb0773bd73d9864925dcc47f1f0810e33ba Fixes: #3830
* Memoize load_path in all cases, run quick populators for path changeMike Bayer2016-10-171-9/+33
| | | | | | | | | | | | | | | | | | | | | | | | Adds a new variant to the "isnew" state within entity loading for isnew=False, but the load path is new. This is to address the use case of an entity appearing in multiple places in the row in a more generalized way than the fixes in [ticket:3431], [ticket:3811] in that loading.py will be able to tell the populator that this row is not "isnew" but is a "new" path for the entity. For the moment, the new information is only being applied to the use of "quick" populators so that simple column loads can take place on top of a deferred loader from elsewhere in the row. As part of this change, state.load_path() will now always be populated with the "path" that was in effect when this state was originally loaded, which for multi-path loads of the same entity is still non-deterministic. Ideally there'd be some kind of "here's all the paths that loaded this state and how" type of data structure though it's not clear if that could be done while maintaining performance. Fixes: #3822 Change-Id: Ib915365353dfcca09e15c24001a8581113b97d5e
* Assemble "don't joinedload other side" rule using query._current_pathMike Bayer2016-10-172-1/+12
| | | | | | | | | 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
* spelling: Postgresql -> PostgreSQLVille Skyttä2016-10-081-3/+3
|
* Spelling fixesVille Skyttä2016-10-081-1/+1
|
* Check for __clause_element__() in ORM insert/updateMike Bayer2016-10-051-4/+8
| | | | | | | | | | | | | | | | ORM attributes can now be assigned any object that is has a ``__clause_element__()`` attribute, which will result in inline SQL the way any :class:`.ClauseElement` class does. This covers other mapped attributes not otherwise transformed by further expression constructs. As part of this, it was considered that we could add __clause_element__() to ClauseElement, however this causes endless loops in a "while" pattern and this pattern has been identified in third party libraries. Add a test to ensure we never make that change. Change-Id: I9e15b3f1c4883fd3909acbf7dc81d034c6e3ce1d Fixes: #3802
* Merge "Enhance "raise" strategy to include "raise_on_sql" option"mike bayer2016-10-046-72/+83
|\
| * Enhance "raise" strategy to include "raise_on_sql" optionMike Bayer2016-10-046-72/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Honor additional row coming in with value of NoneMike Bayer2016-10-041-13/+13
|/ | | | | | | | | | | The change in #3431 still checks that the instance() is non-None, deferring to other loading schemes if it is. These columns are dedicated towards the entity however, so if the value is None, we should set it. If it conflicts, we are detecting that in any case. Change-Id: I223768e2898e843f953e910da1f9564b137d95e4 Fixes: #3811
* Ensure strong ref to obj before calling persistent_to_deleted, othersMike Bayer2016-10-032-5/+23
| | | | | | | | | | | | Add checks in spots where state.obj() might be late-GC'ed before we get a chance to call the event. There may be more cases of these which we should address as they come up. The Session should always be maintaining strong refs to objects that have pending operations left on them, so for these cases we need to ensure that ref remains long enough for the event to be called. Change-Id: I1a7c7bc57130acc11f54ad55924af2e36ac75101 Fixes: #3808
* - improve documentation for SessionTransaction re: parentMike Bayer2016-09-242-10/+111
| | | | | | | | | | and nested attributes and what these mean - improve linking for after_transaction_create() / after_transaction_end() events - add public .parent attribute to detect top-level transaction within these events Change-Id: Ie7382bc8fe5de226160dcb6a5019e19fcc5af38e
* Ensure mapper.polymorphic_on is polymorphic_prop.columns[0]Mike Bayer2016-09-211-11/+8
| | | | | | | | | Fixed bug where joined eager loading would fail for a polymorphically- loaded mapper, where the polymorphic_on was set to an un-mapped expression such as a CASE expression. Change-Id: Iffe68196aaac592165c89684f09f4c06cd78ce54 Fixes: #3800
* Merge "Add the "triggering mapper" to the configure_mappers error message."mike bayer2016-09-201-2/+3
|\
| * Add the "triggering mapper" to the configure_mappers error message.John Perkins2016-09-201-2/+3
| | | | | | | | | | | | | | | | | | | | 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
* | Merge "Allow SQL expressions to be set on PK columns"mike bayer2016-09-201-9/+19
|\ \
| * | Allow SQL expressions to be set on PK columnsMike Bayer2016-09-201-9/+19
| |/ | | | | | | | | | | | | | | | | | | | | | | | | Removes an unnecessary transfer of modified PK column value to the params dictionary, so that if the modified PK column is already present in value_params, this remains in effect. Also propagate a new flag through to _emit_update_statements() that will trip "return_defaults()" across the board if a PK col w/ SQL expression change is present, and pull this PK value in _postfetch as well assuming we're an UPDATE. Change-Id: I9ae87f964df9ba8faea8e25e96b8327f968e5d1b Fixes: #3801
* | Merge "Support bindparam() with callable for primaryjoin"mike bayer2016-09-201-1/+1
|\ \
| * | Support bindparam() with callable for primaryjoinMike Bayer2016-09-191-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | Fixes the comparison of bindparam() objects based on the "callable" parameter being present which helps to correctly detect use_get, and also checks for "callable" when detecting parameters for value substitution and will not impact the object if present. Change-Id: I4c93ee5d404d2648dd9835beeae0c5fb67e37d19 Fixes: #3767
* | Fix ArgumentError access in Session._add_bindMike Bayer2016-09-191-6/+4
|/ | | | | | Fixes: #3798 Change-Id: Ib4e6344b599e871f9d46d36a5aeb7ba3104dc99b Pull-request: https://github.com/zzzeek/sqlalchemy/pull/293
* - also caveats for update() / delete() regarding singleMike Bayer2016-09-121-0/+10
| | | | | | | table inheritance Change-Id: If1511812a22a53537409f902f73e2e52ae3e4a3d (cherry picked from commit 992344334328dba385fe6aa7694cfe3c13adc9d6)
* - add caveat for bulk deletes that they are generally not feasibleMike Bayer2016-09-121-0/+26
| | | | | | for joined inheritance Change-Id: I043a5842401d586aa3ff96d05e06b443ff03fa60
* Provide more informative error when joining with no entitiespr/304Michael Williamson2016-08-281-2/+7
|
* Raise when two validators conflictMike Bayer2016-08-261-0/+5
| | | | | | | | Two @validates decorators that make use of the same name is not supported. Raise an exception. Change-Id: Ia3e89ffdc9ef345a0de258e2ac0ac5e0bd421c61 Fixes: #3776
* Merge remote-tracking branch 'origin/pr/299'Mike Bayer2016-08-161-1/+1
|\
| * Spelling fixespr/299Ville Skyttä2016-08-081-1/+1
| |
* | Rework _apply_joins(), _prep_for_joins() totallyMike Bayer2016-08-151-43/+47
| | | | | | | | | | | | | | | | | | | | | | | | The approach here is still error prone and hard to follow. Reorganize the whole thing to take a pretty blunt approach to the structure of to_join(). Also fix some never-called code (!) in _prep_for_joins() and ensure we re-use an aliased object. Fixes: #3774 Change-Id: Ie6319415ae7213b4a33eac2ab70803ad2880d340
* | Ensure final link in subqueryload join is correctMike Bayer2016-08-121-1/+1
| | | | | | | | | | | | | | | | | | Fixed bug in subquery eager loading where a subqueryload of an "of_type()" object linked to a second subqueryload of a plain mapped class would fail to link the joins correctly. Change-Id: I4be89e6f5e492438464a2ded01eb9c84d7ff7d4e Fixes: #3773
* | - small updates to polymorphic eager loading, cross-link fromMike Bayer2016-08-111-5/+5
|/ | | | | | loading documentation Change-Id: I3ce7e2cc521c4dd155195819a919017d4cc63b3c
* Clarify order_by(False)Mike Bayer2016-07-291-5/+4
| | | | | | | | It wasn't clear how this differs from order_by(None); add more tests and document that this has to do with whether or not mapper.order_by will be re-enabled as well. Change-Id: I332e8ac60c999b38c5a243f1cb72de3cf77891b6
* Allow None to cancel Query.group_by()Iuri Diniz2016-07-291-1/+15
| | | | | | | | | | | This replicates the same behavior as order_by(). order_by() will also be updated to deprecate passing of False as this is no longer functionally different than passing None. Change-Id: I2fc05d0317d28b6c83373769a48f7eea32d56290 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/297
* Allow Table._reset_exported to silently passMike Bayer2016-07-241-2/+0
| | | | | | | | | | | Fixed bug in :class:`.Table` where the internal method ``_reset_exported()`` would corrupt the state of the object. This method is intended for selectable objects and is called by the ORM in some cases; an erroneous mapper configuration would could lead the ORM to call this on on a :class:`.Table` object. Change-Id: I63fa34ee0cdf16358bb125c556390df79758bcbc Fixes: #3755
* Remove same-named relationship warningMike Bayer2016-07-191-11/+0
| | | | | | | | | | Removed a warning that dates back to 0.4 which emits when a same-named relationship is placed on two mappers that inherits via joined or single table inheritance. The warning does not apply to the current unit of work implementation. Change-Id: If528ec3a2f4dc60712d9044fd1ec6c4dfbf0eadb Fixes: #3749
* Use the "committed" values when extracting many-to-one lazyload valueMike Bayer2016-06-081-2/+6
| | | | | | | | | | | | | | | The scalar object set() method calls upon the lazy loader to get at the "old" value of the attriute, however doesn't ensure that the "committed" value of the foreign key attributes is used. If the user has manipulated these attributes and they themselves have pending, non committed changes, we get the "new" value which these attributes would have set up if they were flushed. "old" vs "new" value is always about how the value has changed since the load, so we always have to use the DB-persisted values for everything when looking for "old". Change-Id: I82bdc40ad0cf033c3a98f3361776cf3161542cd6 Fixes: #3708
* Add 'FOR NO KEY UPDATE' / 'FOR KEY SHARE' support for PostgresqlSergey Skopin2016-06-081-2/+3
| | | | | | | | Adds ``key_share=True`` for with_for_update(). Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: I74e0c3fcbc023e1dc98a1fa0c7db67b4c3693a31 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/279
* Add "render_nulls" flag to bulk_insert as optional performance optimizationtsauerwein2016-06-062-10/+39
| | | | | | | | | | | | | | Currently, ``Session.bulk_insert_mappings`` omits NULL values which causes it to break up batches of inserts based on which batches contain NULL and which do not. By adding this flag, the same columns are rendered in the INSERT for all rows allowing them to be batched. The downside is that server-side defaults are omitted. Doctext-author: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: Iec5969304d4bdbf57290b200331bde02254aa3a5 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/243
* Merge "Add SKIP LOCKED support for Postgresql, Oracle"mike bayer2016-06-031-2/+4
|\
| * Add SKIP LOCKED support for Postgresql, OracleJack Zhou2016-06-021-2/+4
| | | | | | | | | | | | | | | | This adds `SELECT ... FOR UPDATE SKIP LOCKED`/ `SELECT ... FOR SHARE SKIP LOCKED` rendering. Change-Id: Id1dc4f1cafc1de23f397a6f73d54ab2c58d5910d Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/86
* | Add an init_scalar event for attributesMike Bayer2016-06-022-5/+114
|/ | | | | | | | | This allows us to build default-setting recipes such as one that allows us to actively read column-level defaults. An example suite is also added. Change-Id: I7b022d52cc89526132d5bc4201ac27fea4cf088d Fixes: #1311
* Merge remote-tracking branch 'origin/pr/270'Mike Bayer2016-05-241-1/+1
|\
| * Spelling fixes: "the a"Ville Skyttä2016-05-051-1/+1
| |
* | Accommodate "callable" bound param in evaluatorMike Bayer2016-05-161-1/+4
| | | | | | | | | | | | | | | | | | | | Fixed bug in "evaluate" strategy of :meth:`.Query.update` and :meth:`.Query.delete` which would fail to accommodate a bound parameter with a "callable" value, as which occurs when filtering by a many-to-one equality expression along a relationship. Change-Id: I47758d3f5d8b9ea1a07e23166780d5f3c32b17f1 Fixes: #3700
* | Check for duplicate calls to register_attribute_implMike Bayer2016-05-101-3/+15
| | | | | | | | | | | | | | | | | | | | Fixed bug whereby the event listeners used for backrefs could be inadvertently applied multiple times, when using a deep class inheritance hierarchy in conjunction with mutiple mapper configuration steps. Change-Id: I712beaf4674e2323bf5b282922658020a6d00b53 Fixes: #3710
* | Repair _orm_columns() to accommodate text()Mike Bayer2016-05-051-1/+1
|/ | | | | | | | | Fixed bug whereby passing a :func:`.text` construct to the :meth:`.Query.group_by` method would raise an error, instead of intepreting the object as a SQL fragment. Change-Id: I5fc2f590b76508d52e23b5fa9cf037ddea8080c3 fixes: #3706
* Corrects some references in ORM documentation.pr/267Jeffrey Finkelstein2016-05-031-8/+10
|
* Merge "Deprecate Mapper.order_by"mike bayer2016-04-191-0/+9
|\
| * Deprecate Mapper.order_byMike Bayer2016-04-191-0/+9
| | | | | | | | | | | | | | | | | | | | | | 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
* | Rename Query._mapper_zero() to Query._entity_zero()Mike Bayer2016-04-191-17/+15
|/ | | | | | | | | | | | To be more descriptive of the use of _mapper_zero(), rename it to _entity_zero(), but also supply a new _mapper_zero() function that more strictly returns a mapper. The existing _entity_zero() function is renamed to _query_entity_zero. _only_mapper_zero() is removed as it isn't used. Divide up the existing calling functions to refer to the appropriate new method. Change-Id: I8780c3235e87b4936c6daf64d9d299b22b6e1260 Fixes: #3608
* Add raise/raiseload relationship loading strategyAdrian Moennich2016-04-194-0/+65
| | | | | | | Fixes: #3512 Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: Ibd126c50eda621e2f4120ee378f7313af2d7ec3c Pull-request: https://github.com/zzzeek/sqlalchemy/pull/193
* Fix typo from "addreses" to "addresses"Rachid Belaid2016-04-061-1/+1
|