since
450f5c0d6519a439f4025c3892fe4c we've been seeing
errors during the uninstrument_class event where first
we saw an internal weakref being collected earlier than seen,
then fixing that we saw the listener collection changing during
iteration for similar reasons.
we would assume the issue is because of the interaction between
mapper / instrumentation/ registry during a test teardown
and the usage of the uninstrument_class event within this
interaction. this interaction is too fundamental to be
relying upon this event in any case and when I wrote this
new code i was planning on changing that part in any case,
I just forgot.
Change-Id: I15744e01bb4d3349bfd529593ebd23eae658eaab
"""
with mapperlib._CONFIGURE_MUTEX:
while _mapper_registry:
- mapper, b = _mapper_registry.popitem()
- mapper.dispose()
+ try:
+ mapper, b = _mapper_registry.popitem()
+ except KeyError:
+ # weak registry, item could have been collected
+ pass
+ else:
+ mapper.dispose()
joinedload = strategy_options.joinedload._unbound_fn
self.metadata = lcl_metadata
self.constructor = constructor
- def _dispose_declarative_artifacts(self, cls):
+ def _dispose_cls(self, cls):
clsregistry.remove_class(cls.__name__, cls, self._class_registry)
def generate_base(
init_method=registry.constructor,
)
- event.listen(
- cls_,
- "class_uninstrument",
- registry._dispose_declarative_artifacts,
- )
-
def set_cls_attribute(self, attrname, value):
manager = instrumentation.manager_of_class(self.cls)
def listen(target_cls, *arg):
listen_cls = target()
+
+ # if weakref were collected, however this is not something
+ # that normally happens. it was occurring during test teardown
+ # between mapper/registry/instrumentation_manager, however this
+ # interaction was changed to not rely upon the event system.
if listen_cls is None:
return None
and self.class_manager.is_mapped
and self.class_manager.mapper is self
):
+ self.class_manager.registry._dispose_cls(self.class_)
instrumentation.unregister_class(self.class_)
def _configure_pks(self):