diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-14 15:41:31 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-14 15:41:31 -0400 |
| commit | 800efc75256283770d5c28ddd99f26f341733698 (patch) | |
| tree | 195206da35d9f2d434e9bd35596038ecaab1e832 /lib/sqlalchemy/orm/mapper.py | |
| parent | 6dad6332cd0b777e4d876f51fada4fdf31299c53 (diff) | |
| download | sqlalchemy-800efc75256283770d5c28ddd99f26f341733698.tar.gz | |
- [feature] *Very limited* support for
inheriting mappers to be GC'ed when the
class itself is deferenced. The mapper
must not have its own table (i.e.
single table inh only) without polymorphic
attributes in place.
This allows for the use case of
creating a temporary subclass of a declarative
mapped class, with no table or mapping
directives of its own, to be garbage collected
when dereferenced by a unit test.
[ticket:2526]
Diffstat (limited to 'lib/sqlalchemy/orm/mapper.py')
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 76d6b1165..57c8de498 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -431,7 +431,7 @@ class Mapper(object): being present.""" # a set of all mappers which inherit from this one. - self._inheriting_mappers = set() + self._inheriting_mappers = util.WeakSet() if self.inherits: if isinstance(self.inherits, type): @@ -1308,7 +1308,6 @@ class Mapper(object): tables = set(sql_util.find_tables(selectable, include_aliases=True)) mappers = [m for m in mappers if m.local_table in tables] - return mappers def _selectable_from_mappers(self, mappers, innerjoin): @@ -1383,7 +1382,7 @@ class Mapper(object): @_memoized_configured_property def _polymorphic_properties(self): - return tuple(self._iterate_polymorphic_properties( + return list(self._iterate_polymorphic_properties( self._with_polymorphic_mappers)) def _iterate_polymorphic_properties(self, mappers=None): @@ -1401,8 +1400,10 @@ class Mapper(object): # from other mappers, as these are sometimes dependent on that # mapper's polymorphic selectable (which we don't want rendered) for c in util.unique_list( - chain(*[list(mapper.iterate_properties) for mapper in [self] + - mappers]) + chain(*[ + list(mapper.iterate_properties) for mapper in + [self] + mappers + ]) ): if getattr(c, '_is_polymorphic_discriminator', False) and \ (self.polymorphic_on is None or @@ -1587,7 +1588,7 @@ class Mapper(object): item = stack.popleft() descendants.append(item) stack.extend(item._inheriting_mappers) - return tuple(descendants) + return util.WeakSequence(descendants) def polymorphic_iterator(self): """Iterate through the collection including this mapper and |
