]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- blow away context._attributes
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 2 Jun 2013 16:06:39 +0000 (12:06 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 2 Jun 2013 16:06:39 +0000 (12:06 -0400)
- to account for query._attributes/context.attributes, just pass
the attributes dict directly to the PathRegistry methods

lib/sqlalchemy/orm/interfaces.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/orm/strategies.py
lib/sqlalchemy/orm/util.py
test/orm/test_utils.py

index a814044018f226a49d00566b60389ccdf96c623a..396f234c43db4e19699ac1546d9d4e7e3e67facb 100644 (file)
@@ -745,7 +745,7 @@ class PropertyOption(MapperOption):
                                 ext_info.mapper, aliased=True,
                                 _use_mapper_path=True)
                     ext_info = inspect(ac)
-                path.set(query, "path_with_polymorphic", ext_info)
+                path.set(query._attributes, "path_with_polymorphic", ext_info)
             else:
                 path_element = mapper = getattr(prop, 'mapper', None)
                 if mapper is None and tokens:
@@ -776,13 +776,13 @@ class StrategizedOption(PropertyOption):
         if self.chained:
             for path in paths:
                 path.set(
-                    query,
+                    query._attributes,
                     "loaderstrategy",
                     strategy
                 )
         else:
             paths[-1].set(
-                query,
+                query._attributes,
                 "loaderstrategy",
                 strategy
             )
index 79fd61c63940b3e2cdf247a66886d1a9bfc45c16..beae7aba0b3d317e4f236b3717fc6312c094ec85 100644 (file)
@@ -3186,7 +3186,7 @@ class QueryContext(object):
         self.create_eager_joins = []
         self.propagate_options = set(o for o in query._with_options if
                                         o.propagate_to_loaders)
-        self.attributes = self._attributes = query._attributes.copy()
+        self.attributes = query._attributes.copy()
 
 
 class AliasOption(interfaces.MapperOption):
index 48ee6a5f8f8d047de802daf6757c3358351ed535..cabfb35b96b440dd18cf5f95b5f34e3b29125cee 100644 (file)
@@ -688,7 +688,8 @@ class SubqueryLoader(AbstractRelationshipLoader):
 
         # build up a path indicating the path from the leftmost
         # entity to the thing we're subquery loading.
-        with_poly_info = path.get(context, "path_with_polymorphic", None)
+        with_poly_info = path.get(context.attributes,
+                                "path_with_polymorphic", None)
         if with_poly_info is not None:
             effective_entity = with_poly_info.entity
         else:
@@ -701,7 +702,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
 
         # if not via query option, check for
         # a cycle
-        if not path.contains(context, "loaderstrategy"):
+        if not path.contains(context.attributes, "loaderstrategy"):
             if self.join_depth:
                 if path.length / 2 > self.join_depth:
                     return
@@ -747,7 +748,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
 
         # add new query to attributes to be picked up
         # by create_row_processor
-        path.set(context, "subquery", q)
+        path.set(context.attributes, "subquery", q)
 
     def _get_leftmost(self, subq_path):
         subq_path = subq_path.path
@@ -924,7 +925,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
 
         path = path[self.parent_property]
 
-        subq = path.get(context, 'subquery')
+        subq = path.get(context.attributes, 'subquery')
 
         if subq is None:
             return None, None, None
@@ -934,7 +935,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
         # cache the loaded collections in the context
         # so that inheriting mappers don't re-load when they
         # call upon create_row_processor again
-        collections = path.get(context, "collections")
+        collections = path.get(context.attributes, "collections")
         if collections is None:
             collections = dict(
                     (k, [v[0] for v in v])
@@ -942,7 +943,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
                         subq,
                         lambda x: x[1:]
                     ))
-            path.set(context, 'collections', collections)
+            path.set(context.attributes, 'collections', collections)
 
         if adapter:
             local_cols = [adapter.columns[c] for c in local_cols]
@@ -1011,7 +1012,7 @@ class JoinedLoader(AbstractRelationshipLoader):
 
         with_polymorphic = None
 
-        user_defined_adapter = path.get(context,
+        user_defined_adapter = path.get(context.attributes,
                                 "user_defined_eager_row_processor",
                                 False)
         if user_defined_adapter is not False:
@@ -1023,7 +1024,7 @@ class JoinedLoader(AbstractRelationshipLoader):
         else:
             # if not via query option, check for
             # a cycle
-            if not path.contains(context, "loaderstrategy"):
+            if not path.contains(context.attributes, "loaderstrategy"):
                 if self.join_depth:
                     if path.length / 2 > self.join_depth:
                         return
@@ -1037,7 +1038,7 @@ class JoinedLoader(AbstractRelationshipLoader):
                 )
 
         with_poly_info = path.get(
-            context,
+            context.attributes,
             "path_with_polymorphic",
             None
         )
@@ -1065,11 +1066,11 @@ class JoinedLoader(AbstractRelationshipLoader):
             adapter = entity._get_entity_clauses(context.query, context)
             if adapter and user_defined_adapter:
                 user_defined_adapter = user_defined_adapter.wrap(adapter)
-                path.set(context, "user_defined_eager_row_processor",
+                path.set(context.attributes, "user_defined_eager_row_processor",
                                         user_defined_adapter)
             elif adapter:
                 user_defined_adapter = adapter
-                path.set(context, "user_defined_eager_row_processor",
+                path.set(context.attributes, "user_defined_eager_row_processor",
                                         user_defined_adapter)
 
             add_to_collection = context.primary_columns
@@ -1080,7 +1081,7 @@ class JoinedLoader(AbstractRelationshipLoader):
         column_collection, parentmapper, allow_innerjoin
     ):
         with_poly_info = path.get(
-            context,
+            context.attributes,
             "path_with_polymorphic",
             None
         )
@@ -1098,7 +1099,7 @@ class JoinedLoader(AbstractRelationshipLoader):
         if self.parent_property.direction != interfaces.MANYTOONE:
             context.multi_row_eager_loaders = True
 
-        innerjoin = allow_innerjoin and path.get(context,
+        innerjoin = allow_innerjoin and path.get(context.attributes,
                             "eager_join_type",
                             self.parent_property.innerjoin)
         if not innerjoin:
@@ -1113,7 +1114,7 @@ class JoinedLoader(AbstractRelationshipLoader):
         )
 
         add_to_collection = context.secondary_columns
-        path.set(context, "eager_row_processor", clauses)
+        path.set(context.attributes, "eager_row_processor", clauses)
 
         return clauses, adapter, add_to_collection, allow_innerjoin
 
@@ -1208,7 +1209,7 @@ class JoinedLoader(AbstractRelationshipLoader):
                                 )
 
     def _create_eager_adapter(self, context, row, adapter, path):
-        user_defined_adapter = path.get(context,
+        user_defined_adapter = path.get(context.attributes,
                                 "user_defined_eager_row_processor",
                                 False)
         if user_defined_adapter is not False:
@@ -1221,7 +1222,7 @@ class JoinedLoader(AbstractRelationshipLoader):
             elif context.adapter:
                 decorator = context.adapter
         else:
-            decorator = path.get(context, "eager_row_processor")
+            decorator = path.get(context.attributes, "eager_row_processor")
             if decorator is None:
                 return False
 
@@ -1374,9 +1375,9 @@ class EagerJoinOption(PropertyOption):
     def process_query_property(self, query, paths):
         if self.chained:
             for path in paths:
-                path.set(query, "eager_join_type", self.innerjoin)
+                path.set(query._attributes, "eager_join_type", self.innerjoin)
         else:
-            paths[-1].set(query, "eager_join_type", self.innerjoin)
+            paths[-1].set(query._attributes, "eager_join_type", self.innerjoin)
 
 
 class LoadEagerFromAliasOption(PropertyOption):
@@ -1395,7 +1396,7 @@ class LoadEagerFromAliasOption(PropertyOption):
             for path in paths[0:-1]:
                 (root_mapper, prop) = path.path[-2:]
                 adapter = query._polymorphic_adapters.get(prop.mapper, None)
-                path.setdefault(query,
+                path.setdefault(query._attributes,
                             "user_defined_eager_row_processor",
                             adapter)
 
@@ -1403,21 +1404,24 @@ class LoadEagerFromAliasOption(PropertyOption):
         if self.alias is not None:
             if isinstance(self.alias, str):
                 self.alias = prop.target.alias(self.alias)
-            paths[-1].set(query, "user_defined_eager_row_processor",
-                sql_util.ColumnAdapter(self.alias,
+            paths[-1].set(query._attributes,
+                    "user_defined_eager_row_processor",
+                    sql_util.ColumnAdapter(self.alias,
                                 equivalents=prop.mapper._equivalent_columns)
             )
         else:
-            if paths[-1].contains(query, "path_with_polymorphic"):
-                with_poly_info = paths[-1].get(query, "path_with_polymorphic")
+            if paths[-1].contains(query._attributes, "path_with_polymorphic"):
+                with_poly_info = paths[-1].get(query._attributes,
+                                                "path_with_polymorphic")
                 adapter = orm_util.ORMAdapter(
                             with_poly_info.entity,
                             equivalents=prop.mapper._equivalent_columns,
                             adapt_required=True)
             else:
                 adapter = query._polymorphic_adapters.get(prop.mapper, None)
-            paths[-1].set(query, "user_defined_eager_row_processor",
-                                    adapter)
+            paths[-1].set(query._attributes,
+                                "user_defined_eager_row_processor",
+                                adapter)
 
 
 def single_parent_validator(desc, prop):
index ddc0dd81822e9d4c9a7fdabe7b91eb29ca867524..bd8228f2c1cd39b39dbc29d7574625a8a72dba78 100644 (file)
@@ -278,16 +278,16 @@ class PathRegistry(object):
         return other is not None and \
             self.path == other.path
 
-    def set(self, reg, key, value):
-        reg._attributes[(key, self.path)] = value
+    def set(self, attributes, key, value):
+        attributes[(key, self.path)] = value
 
-    def setdefault(self, reg, key, value):
-        reg._attributes.setdefault((key, self.path), value)
+    def setdefault(self, attributes, key, value):
+        attributes.setdefault((key, self.path), value)
 
-    def get(self, reg, key, value=None):
+    def get(self, attributes, key, value=None):
         key = (key, self.path)
-        if key in reg._attributes:
-            return reg._attributes[key]
+        if key in attributes:
+            return attributes[key]
         else:
             return value
 
@@ -313,8 +313,8 @@ class PathRegistry(object):
         else:
             return False
 
-    def contains(self, reg, key):
-        return (key, self.path) in reg._attributes
+    def contains(self, attributes, key):
+        return (key, self.path) in attributes
 
     def __reduce__(self):
         return _unreduce_path, (self.serialize(), )
@@ -441,8 +441,8 @@ class EntityRegistry(PathRegistry, dict):
         """
         path = dict.__getitem__(self, prop)
         path_key = (key, path.path)
-        if path_key in context._attributes:
-            return context._attributes[path_key]
+        if path_key in context.attributes:
+            return context.attributes[path_key]
         else:
             return None
 
index e0059eef93e6d58eb2d7cb9404724109f1a9471c..49ff61ea064655f7c5dda1e3e877668cd0e1c3a3 100644 (file)
@@ -370,13 +370,6 @@ class PathRegistryTest(_fixtures.FixtureTest):
         assert p1.contains_mapper(umapper)
         assert not p1.contains_mapper(amapper)
 
-    def _registry(self):
-        class Reg(dict):
-            @property
-            def _attributes(self):
-                return self
-        return Reg()
-
     def test_path(self):
         umapper = inspect(self.classes.User)
         amapper = inspect(self.classes.Address)
@@ -396,7 +389,7 @@ class PathRegistryTest(_fixtures.FixtureTest):
         )
 
     def test_registry_set(self):
-        reg = self._registry()
+        reg = {}
         umapper = inspect(self.classes.User)
         amapper = inspect(self.classes.Address)
 
@@ -417,7 +410,7 @@ class PathRegistryTest(_fixtures.FixtureTest):
         )
 
     def test_registry_get(self):
-        reg = self._registry()
+        reg = {}
         umapper = inspect(self.classes.User)
         amapper = inspect(self.classes.Address)
 
@@ -439,7 +432,7 @@ class PathRegistryTest(_fixtures.FixtureTest):
         eq_(p3.get(reg, "p1key"), None)
 
     def test_registry_contains(self):
-        reg = self._registry()
+        reg = {}
         umapper = inspect(self.classes.User)
         amapper = inspect(self.classes.Address)
 
@@ -459,7 +452,7 @@ class PathRegistryTest(_fixtures.FixtureTest):
         assert not p2.contains(reg, "fake")
 
     def test_registry_setdefault(self):
-        reg = self._registry()
+        reg = {}
         umapper = inspect(self.classes.User)
         amapper = inspect(self.classes.Address)