[hooks] build EnsureSymmetricRelations{Add,Delete} dynamically
Instead of setting the __select__ attribute at registration time, which
confuses the filterable_selectors cache when running different tests (with
different schemas) in the same process, just make entirely new classes.
Closes #8785708.
--- a/hooks/integrity.py Thu Nov 26 11:30:54 2015 +0100
+++ b/hooks/integrity.py Mon Nov 30 15:53:35 2015 +0100
@@ -111,9 +111,10 @@
category = 'integrity'
-class EnsureSymmetricRelationsAdd(hook.Hook):
+class _EnsureSymmetricRelationsAdd(hook.Hook):
""" ensure X r Y => Y r X iff r is symmetric """
__regid__ = 'cw.add_ensure_symmetry'
+ __abstract__ = True
category = 'activeintegrity'
events = ('after_add_relation',)
# __select__ is set in the registration callback
@@ -123,9 +124,10 @@
self.rtype, self.eidfrom)
-class EnsureSymmetricRelationsDelete(hook.Hook):
+class _EnsureSymmetricRelationsDelete(hook.Hook):
""" ensure X r Y => Y r X iff r is symmetric """
__regid__ = 'cw.delete_ensure_symmetry'
+ __abstract__ = True
category = 'activeintegrity'
events = ('after_delete_relation',)
# __select__ is set in the registration callback
@@ -337,5 +339,9 @@
vreg.register_all(globals().values(), __name__)
symmetric_rtypes = [rschema.type for rschema in vreg.schema.relations()
if rschema.symmetric]
- EnsureSymmetricRelationsAdd.__select__ = hook.Hook.__select__ & hook.match_rtype(*symmetric_rtypes)
- EnsureSymmetricRelationsDelete.__select__ = hook.Hook.__select__ & hook.match_rtype(*symmetric_rtypes)
+ class EnsureSymmetricRelationsAdd(_EnsureSymmetricRelationsAdd):
+ __select__ = _EnsureSymmetricRelationsAdd.__select__ & hook.match_rtype(*symmetric_rtypes)
+ vreg.register(EnsureSymmetricRelationsAdd)
+ class EnsureSymmetricRelationsDelete(_EnsureSymmetricRelationsDelete):
+ __select__ = _EnsureSymmetricRelationsDelete.__select__ & hook.match_rtype(*symmetric_rtypes)
+ vreg.register(EnsureSymmetricRelationsDelete)