diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-08-06 19:30:34 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-08-06 19:30:34 -0400 |
| commit | e548b7f8ffd29a909c9b02e1ff5e307aa6ee7b0b (patch) | |
| tree | e952de9de167ac0825c2552aba632051aaad25c4 /lib/sqlalchemy | |
| parent | 4abcc0da839a57513f18a7a9ea7ee6918d48e4b1 (diff) | |
| download | sqlalchemy-e548b7f8ffd29a909c9b02e1ff5e307aa6ee7b0b.tar.gz | |
- Repaired edge case where mapper would fail
to fully update internal state when a relationship
on a new mapper would establish a backref on the
first mapper.
- continuing with tutorial, moving eager loading into its
own place and describing more fully
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 27 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/properties.py | 1 |
2 files changed, 22 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index becc47052..5a2ca6ed4 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -48,6 +48,7 @@ _none_set = frozenset([None]) _memoized_configured_property = util.group_expirable_memoized_property() + # a constant returned by _get_attr_by_column to indicate # this mapper is not handling an attribute for a particular # column @@ -1029,6 +1030,8 @@ class Mapper(object): prop.init() prop.post_instrument_class(self) + if self.configured: + self._expire_memoizations() def _post_configure_properties(self): """Call the ``init()`` method on all ``MapperProperties`` @@ -1072,7 +1075,6 @@ class Mapper(object): """ self._init_properties[key] = prop self._configure_property(key, prop, init=self.configured) - self._expire_memoizations() def _expire_memoizations(self): for mapper in self.iterate_to_root(): @@ -2802,7 +2804,12 @@ def _event_on_load(state, ctx): instrumenting_mapper._reconstructor(state.obj()) def _event_on_first_init(manager, cls): - """Trigger mapper compilation.""" + """Initial mapper compilation trigger. + + instrumentation calls this one when InstanceState + is first generated, and is needed for legacy mutable + attributes to work. + """ instrumenting_mapper = manager.info.get(_INSTRUMENTOR) if instrumenting_mapper: @@ -2810,12 +2817,20 @@ def _event_on_first_init(manager, cls): configure_mappers() def _event_on_init(state, args, kwargs): - """Run init_instance hooks.""" + """Run init_instance hooks. + + This also includes mapper compilation, normally not needed + here but helps with some piecemeal configuration + scenarios (such as in the ORM tutorial). + + """ instrumenting_mapper = state.manager.info.get(_INSTRUMENTOR) - if instrumenting_mapper and \ - instrumenting_mapper._set_polymorphic_identity: - instrumenting_mapper._set_polymorphic_identity(state) + if instrumenting_mapper: + if _new_mappers: + configure_mappers() + if instrumenting_mapper._set_polymorphic_identity: + instrumenting_mapper._set_polymorphic_identity(state) def _event_on_resurrect(state): # re-populate the primary key elements diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 4de438e55..de532794c 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -1406,6 +1406,7 @@ class RelationshipProperty(StrategizedProperty): **kwargs ) mapper._configure_property(backref_key, relationship) + if self.back_populates: self._add_reverse_property(self.back_populates) |
