]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed bug whereby populate_existing
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 16 Jun 2012 21:41:38 +0000 (17:41 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 16 Jun 2012 21:41:38 +0000 (17:41 -0400)
option would not propagate to subquery
eager loaders.  [ticket:2497].

CHANGES
lib/sqlalchemy/orm/strategies.py
test/orm/test_subquery_relations.py

diff --git a/CHANGES b/CHANGES
index e1148ae18991550fafb90d544b46177124b24d1c..48fad189328cbcef5baf72c32f6fb192290ea6bc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,10 @@ CHANGES
     was not accepting a scalar argument 
     for the identity.  [ticket:2508].
 
+  - [bug] Fixed bug whereby populate_existing
+    option would not propagate to subquery
+    eager loaders.  [ticket:2497].
+
 - sql
   - [bug] added BIGINT to types.__all__,
     BIGINT, BINARY, VARBINARY to sqlalchemy
index 9f32cc6a6619e8c5630cfdf1b0662e999696f318..d7d3d57ebdad86110cb01c0ee2e58fdea8e58775 100644 (file)
@@ -897,6 +897,8 @@ class SubqueryLoader(AbstractRelationshipLoader):
         # these will fire relative to subq_path.
         q = q._with_current_path(subq_path)
         q = q._conditional_options(*orig_query._with_options)
+        if orig_query._populate_existing: 
+            q._populate_existing = orig_query._populate_existing
         return q
 
     def _setup_outermost_orderby(self, q):
index 70a015f29fb1240e58bdee655b5915ff584ffe92..90df17609dc0f9d67f53eb994558cd3ae53825a7 100644 (file)
@@ -861,6 +861,18 @@ class LoadOnExistingTest(_fixtures.FixtureTest):
         self.assert_sql_count(testing.db, go, 1)
         assert 'addresses' not in u1.__dict__
 
+    def test_populate_existing_propagate(self):
+        User, Address, sess = self._eager_config_fixture()
+        u1 = sess.query(User).get(8)
+        u1.addresses[2].email_address = "foofoo"
+        del u1.addresses[1]
+        u1 = sess.query(User).populate_existing().filter_by(id=8).one()
+        # collection is reverted
+        eq_(len(u1.addresses), 3)
+
+        # attributes on related items reverted
+        eq_(u1.addresses[2].email_address, "ed@lala.com")
+
     def test_loads_second_level_collection_to_scalar(self):
         User, Address, Dingaling, sess = self._collection_to_scalar_fixture()