- changed status to resolved
remove comparsion in mapper._postfetch
Issue #1015
resolved
heres the patch, which needs test coverage for its basic functionality (i.e. that all attributes are definitely populated), and also needs test coverage for the union against the "VALUES" list. a custom type with a broken comparator should be used in the tests to ensure that user-defined comparators are not involved at all. needs to be in 0.4 and 0.5.
Index: lib/sqlalchemy/orm/mapper.py
===================================================================
--- lib/sqlalchemy/orm/mapper.py (revision 4563)
+++ lib/sqlalchemy/orm/mapper.py (working copy)
@@ -1190,16 +1190,25 @@
which will populate those attributes in one query when next accessed.
"""
- postfetch_cols = util.Set(resultproxy.postfetch_cols()).union(util.Set(value_params.keys()))
- deferred_props = [ # TODO: need test coverage for the "value_params" union here (nothing fails if you remove it)
+ # TODO: change resultproxy.post/prefetch_cols() to attributes
+
+ postfetch_cols = util.Set(resultproxy.postfetch_cols()).union(value_params)
+ generated_cols = util.Set(resultproxy.prefetch_cols())
+
+ if self.polymorphic_on:
+ po = table.corresponding_column(self.polymorphic_on)
+ if po:
+ generated_cols.add(po)
+ if self.version_id_col:
+ generated_cols.add(self.version_id_col)
- for c in self._cols_by_table[table](]
+):
- if c in postfetch_cols and (not c.key in params or c in value_params):
- prop = self._columntoproperty[c](c)
- deferred_props.append(prop.key)
- elif not c.primary_key and c.key in params and self._get_state_attr_by_column(state, c) != params[c.key](c.key):
+ for c in generated_cols:
+ if c.key in params:
self._set_state_attr_by_column(state, c, params[c.key](c.key))
+ deferred_props = [for prop in [self._columntoproperty[c](prop.key) for c in postfetch_cols]]
+
if deferred_props:
if self.eager_defaults:
_instance_key = self._identity_key_from_state(state)
Index: lib/sqlalchemy/engine/base.py
===================================================================
--- lib/sqlalchemy/engine/base.py (revision 4563)
+++ lib/sqlalchemy/engine/base.py (working copy)
@@ -1574,7 +1574,10 @@
See ExecutionContext for details.
"""
return self.context.postfetch_cols
-
+
+ def prefetch_cols(self):
+ return self.context.prefetch_cols
+
def supports_sane_rowcount(self):
"""Return ``supports_sane_rowcount`` from the dialect.
Index: lib/sqlalchemy/engine/default.py
===================================================================
--- lib/sqlalchemy/engine/default.py (revision 4563)
+++ lib/sqlalchemy/engine/default.py (working copy)
@@ -395,3 +395,4 @@
self._last_updated_params = compiled_parameters
self.postfetch_cols = self.compiled.postfetch
+ self.prefetch_cols = self.compiled.prefetch
\ No newline at end of file
Comments (2)
-
reporter -
reporter - removed milestone
Removing milestone: 0.4.6 (automated comment)
- Log in to comment
b089e8615b9cec8b7cb4741b1fad8c30afcfc848 acaf56a37d5a964958afb762d6c8b7a7ae8780ab