summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-06-02 12:06:39 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-06-02 12:06:39 -0400
commit32716eae773e6f6b7f37baf705342c1ed89df461 (patch)
tree0f99019fc9db8cb34b9ba14c0b8469f4cb7d6cd6
parent832d657854f6fca8a1925e89f0ad20d260dc9e45 (diff)
downloadsqlalchemy-32716eae773e6f6b7f37baf705342c1ed89df461.tar.gz
- blow away context._attributes
- to account for query._attributes/context.attributes, just pass the attributes dict directly to the PathRegistry methods
-rw-r--r--lib/sqlalchemy/orm/interfaces.py6
-rw-r--r--lib/sqlalchemy/orm/query.py2
-rw-r--r--lib/sqlalchemy/orm/strategies.py54
-rw-r--r--lib/sqlalchemy/orm/util.py22
-rw-r--r--test/orm/test_utils.py15
5 files changed, 48 insertions, 51 deletions
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index a81404401..396f234c4 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -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
)
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 79fd61c63..beae7aba0 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -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):
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 48ee6a5f8..cabfb35b9 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -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):
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py
index ddc0dd818..bd8228f2c 100644
--- a/lib/sqlalchemy/orm/util.py
+++ b/lib/sqlalchemy/orm/util.py
@@ -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
diff --git a/test/orm/test_utils.py b/test/orm/test_utils.py
index e0059eef9..49ff61ea0 100644
--- a/test/orm/test_utils.py
+++ b/test/orm/test_utils.py
@@ -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)