diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-01-30 01:01:22 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-01-30 01:01:22 +0000 |
commit | d8204ea92abe4b74d99549b89260c616f82e9dc5 (patch) | |
tree | 1b74ed61aaed34c43708771b0832c6da6a705dd2 /lib/sqlalchemy | |
parent | 6f7af7017449fd869594bd06b149061e54d21f08 (diff) | |
download | sqlalchemy-d8204ea92abe4b74d99549b89260c616f82e9dc5.tar.gz |
further work on insuring clear_mappers() really works. assignmapper identified
as a much trickier thing to clean out. added a unit test so that if any new collections get introduced
we are still testing.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/ext/assignmapper.py | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/__init__.py | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/util.py | 4 |
4 files changed, 16 insertions, 3 deletions
diff --git a/lib/sqlalchemy/ext/assignmapper.py b/lib/sqlalchemy/ext/assignmapper.py index 89cf962e7..b76f29943 100644 --- a/lib/sqlalchemy/ext/assignmapper.py +++ b/lib/sqlalchemy/ext/assignmapper.py @@ -39,3 +39,4 @@ def assign_mapper(ctx, class_, *args, **kwargs): for name in ['flush', 'delete', 'expire', 'refresh', 'expunge', 'merge', 'save', 'update', 'save_or_update']: monkeypatch_objectstore_method(ctx, class_, name) return m + diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py index 96890272d..1e1a75b63 100644 --- a/lib/sqlalchemy/orm/__init__.py +++ b/lib/sqlalchemy/orm/__init__.py @@ -74,8 +74,10 @@ def clear_mappers(): when new mappers are created, they will be assigned to their classes as their primary mapper.""" for mapper in mapper_registry.values(): attribute_manager.reset_class_managed(mapper.class_) + mapper.class_key.dispose() + if hasattr(mapper.class_, 'c'): + del mapper.class_.c mapper_registry.clear() - mapperlib.ClassKey.instances.clear() def clear_mapper(m): """remove the given mapper from the storage of mappers. @@ -83,7 +85,11 @@ def clear_mapper(m): when a new mapper is created for the previous mapper's class, it will be used as that classes' new primary mapper.""" del mapper_registry[m.class_key] - + attribute_manager.reset_class_managed(m.class_) + if hasattr(m.class_, 'c'): + del m.class_.c + m.class_key.dispose() + def extension(ext): """return a MapperOption that will insert the given MapperExtension to the beginning of the list of extensions that will be called in the context of the Query. diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index d6967934c..1d4ce6bb9 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1458,7 +1458,9 @@ class ClassKey(object): return self is other def __repr__(self): return "ClassKey(%s, %s)" % (repr(self.class_), repr(self.entity_name)) - + def dispose(self): + type(self).dispose_static(self.class_, self.entity_name) + def has_identity(object): return hasattr(object, '_instance_key') diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 706630918..54b1afa9f 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -49,6 +49,10 @@ def reversed(seq): class ArgSingleton(type): instances = {} + def dispose_static(self, *args): + hashkey = (self, args) + #if hashkey in ArgSingleton.instances: + del ArgSingleton.instances[hashkey] def __call__(self, *args): hashkey = (self, args) try: |