]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed 1.0 regression where the "noload" loader strategy would fail
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 11 Aug 2015 17:05:17 +0000 (13:05 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 11 Aug 2015 17:05:17 +0000 (13:05 -0400)
to function for a many-to-one relationship.  The loader used an
API to place "None" into the dictionary which no longer actually
writes a value; this is a side effect of :ticket:`3061`.
- remove InstanceState._initialize() totally, it's used nowhere
else and no longer does what it says it does
- fill in fowards-port version ids throughout the changes for 1.0.9

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/state.py
lib/sqlalchemy/orm/strategies.py
test/orm/test_mapper.py

index ad9c1473d0200946c0f6ec80dd958d751224d15c..ad8805299588cda5059889b03ff9f9d1116070e1 100644 (file)
 .. changelog::
     :version: 1.0.9
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 3510
+        :versions: 1.1.0b1
+
+        Fixed 1.0 regression where the "noload" loader strategy would fail
+        to function for a many-to-one relationship.  The loader used an
+        API to place "None" into the dictionary which no longer actually
+        writes a value; this is a side effect of :ticket:`3061`.
+
     .. change::
         :tags: bug, sybase
         :tickets: 3508, 3509
+        :versions: 1.1.0b1
 
         Fixed two issues regarding Sybase reflection, allowing tables
         without primary keys to be reflected as well as ensured that
@@ -32,6 +43,7 @@
     .. change::
         :tags: bug, postgresql
         :pullreq: github:190
+        :versions: 1.1.0b1
 
         An adjustment to the new Postgresql feature of reflecting storage
         options and USING of :ticket:`3455` released in 1.0.6,
index a45c22394a1d443e27520d30620a62e2c895a45b..5440d6b5dd2752aa3264a8a75ae8f547be05538a 100644 (file)
@@ -551,6 +551,11 @@ class AttributeImpl(object):
     def initialize(self, state, dict_):
         """Initialize the given state's attribute with an empty value."""
 
+        # As of 1.0, we don't actually set a value in
+        # dict_.  This is so that the state of the object does not get
+        # modified without emitting the appropriate events.
+
+
         return None
 
     def get(self, state, dict_, passive=PASSIVE_OFF):
index 6034e74de082892cb551a5d11344d36707c4ff69..61d1ad29db28f8cfca3165ebb12b1ae623e9e50d 100644 (file)
@@ -374,12 +374,6 @@ class InstanceState(interfaces.InspectionAttr):
 
         state_dict['manager'](self, inst, state_dict)
 
-    def _initialize(self, key):
-        """Set this attribute to an empty value or collection,
-           based on the AttributeImpl in use."""
-
-        self.manager.get_impl(key).initialize(self, self.dict)
-
     def _reset(self, dict_, key):
         """Remove the given attribute and any
            callables associated with it."""
index b9ef5808bb9de5a01e346a8739fe31d9f822ad97..67dac1cccba11195f88c4a09f7fd24a90ba3c663 100644 (file)
@@ -346,7 +346,10 @@ class NoLoader(AbstractRelationshipLoader):
             self, context, path, loadopt, mapper,
             result, adapter, populators):
         def invoke_no_load(state, dict_, row):
-            state._initialize(self.key)
+            if self.uselist:
+                state.manager.get_impl(self.key).initialize(state, dict_)
+            else:
+                dict_[self.key] = None
         populators["new"].append((self.key, invoke_no_load))
 
 
index 8dc23efd077d17c647926ffcfb65a05e520e6f99..6845ababb52c018b9d7ce87cc2f67fc9b0402dda 100644 (file)
@@ -2698,6 +2698,24 @@ class NoLoadTest(_fixtures.FixtureTest):
             {'id': 7, 'addresses': (Address, [{'id': 1}])},
         )
 
+    def test_m2o_noload_option(self):
+        Address, addresses, users, User = (
+            self.classes.Address,
+            self.tables.addresses,
+            self.tables.users,
+            self.classes.User)
+        mapper(Address, addresses, properties={
+            'user': relationship(User)
+        })
+        mapper(User, users)
+        s = Session()
+        a1 = s.query(Address).filter_by(id=1).options(
+            sa.orm.noload('user')).first()
+
+        def go():
+            eq_(a1.user, None)
+        self.sql_count_(0, go)
+
 
 class RequirementsTest(fixtures.MappedTest):