[hooks] build EnsureSymmetricRelations{Add,Delete} dynamically
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 30 Nov 2015 15:53:35 +0100
changeset 10936 c3606b52092c
parent 10935 049209b9e9d6
child 10937 eb05348b0e2d
[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.
hooks/integrity.py
--- 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)