[saem-devel] [PATCH 2 of 6] Fix safety belt in UpdateModificationDateOp

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Jan 27 14:50:17 CET 2017

# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1484932941 -3600
#      Fri Jan 20 18:22:21 2017 +0100
# Node ID 13ca30935a66473433e4afffd158ee0af05be430
# Parent  37af40bc48cbfd2ad7ddb20d214d084623bfabfe
Fix safety belt in UpdateModificationDateOp

It won't detect any loop if it's reset at each iteration.

Also, add a warning when some loop is detected.

diff --git a/hooks.py b/hooks.py
--- a/hooks.py
+++ b/hooks.py
@@ -140,19 +140,22 @@ class UpdateModificationDateOp(hook.Data
     def add_entity(self, entity):
         """Add entity, its parent entities (up to the container root) for update of their
         modification date at commit time.
+        safety_belt = set((entity.eid,))
         while True:
-            safety_belt = set((entity.eid,))
             contained = entity.cw_adapt_to('IContained')
             if contained is None:
                 assert entity.cw_adapt_to('IContainer')
                 entity = contained.parent
-                if entity is None or entity.eid in safety_belt:
+                if entity is None:
+                    break
+                if entity.eid in safety_belt:
+                    self.warning('loop detected implying %s(%s)', entity.cw_etype, entity.eid)

More information about the saem-devel mailing list