[syncschema] only add to the `synchronized` set if all possible updates have been done
authorAurelien Campeas <aurelien.campeas@pythonian.fr>
Wed, 02 Sep 2015 15:24:46 +0200
changeset 10584 743ed2b13a6f
parent 10393 fa4d59b88b29
child 10585 80236876ee4d
[syncschema] only add to the `synchronized` set if all possible updates have been done Otherwise a simple sync_schema(syncprops=False) turns the subsequent sync_schema() calls into a no-op. Closes #6510918.
server/migractions.py
server/test/data/migratedapp/schema.py
server/test/data/schema.py
server/test/unittest_migractions.py
--- a/server/migractions.py	Fri Jun 19 16:05:27 2015 +0200
+++ b/server/migractions.py	Wed Sep 02 15:24:46 2015 +0200
@@ -459,7 +459,8 @@
         rtype = str(rtype)
         if rtype in self._synchronized:
             return
-        self._synchronized.add(rtype)
+        if syncrdefs and syncperms and syncprops:
+            self._synchronized.add(rtype)
         rschema = self.fs_schema.rschema(rtype)
         reporschema = self.repo.schema.rschema(rtype)
         if syncprops:
@@ -490,7 +491,8 @@
         etype = str(etype)
         if etype in self._synchronized:
             return
-        self._synchronized.add(etype)
+        if syncrdefs and syncperms and syncprops:
+            self._synchronized.add(etype)
         repoeschema = self.repo.schema.eschema(etype)
         try:
             eschema = self.fs_schema.eschema(etype)
@@ -582,9 +584,10 @@
         reporschema = self.repo.schema.rschema(rschema)
         if (subjtype, rschema, objtype) in self._synchronized:
             return
-        self._synchronized.add((subjtype, rschema, objtype))
-        if rschema.symmetric:
-            self._synchronized.add((objtype, rschema, subjtype))
+        if syncperms and syncprops:
+            self._synchronized.add((subjtype, rschema, objtype))
+            if rschema.symmetric:
+                self._synchronized.add((objtype, rschema, subjtype))
         rdef = rschema.rdef(subjtype, objtype)
         if rdef.infered:
             return # don't try to synchronize infered relation defs
--- a/server/test/data/migratedapp/schema.py	Fri Jun 19 16:05:27 2015 +0200
+++ b/server/test/data/migratedapp/schema.py	Wed Sep 02 15:24:46 2015 +0200
@@ -108,6 +108,12 @@
 
 
 class Personne(EntityType):
+    __permissions__ = {
+        'read':   ('managers', 'users'), # 'guests' was removed
+        'add':    ('managers', 'users'),
+        'update': ('managers', 'owners'),
+        'delete': ('managers', 'owners')
+    }
     __unique_together__ = [('nom', 'prenom', 'datenaiss')]
     nom    = String(fulltextindexed=True, required=True, maxsize=64)
     prenom = String(fulltextindexed=True, maxsize=64)
--- a/server/test/data/schema.py	Fri Jun 19 16:05:27 2015 +0200
+++ b/server/test/data/schema.py	Wed Sep 02 15:24:46 2015 +0200
@@ -128,6 +128,12 @@
 
 
 class Personne(EntityType):
+    __permissions__ = {
+        'read':   ('managers', 'users', 'guests'), # 'guests' will be removed
+        'add':    ('managers', 'users'),
+        'update': ('managers', 'owners'),
+        'delete': ('managers', 'owners')
+    }
     __unique_together__ = [('nom', 'prenom', 'inline2')]
     nom    = String(fulltextindexed=True, required=True, maxsize=64)
     prenom = String(fulltextindexed=True, maxsize=64)
--- a/server/test/unittest_migractions.py	Fri Jun 19 16:05:27 2015 +0200
+++ b/server/test/unittest_migractions.py	Wed Sep 02 15:24:46 2015 +0200
@@ -410,6 +410,9 @@
             delete_concerne_rqlexpr = self._rrqlexpr_rset(cnx, 'delete', 'concerne')
             add_concerne_rqlexpr = self._rrqlexpr_rset(cnx, 'add', 'concerne')
 
+            # make sure properties (e.g. etype descriptions) are synced by the
+            # second call to sync_schema
+            mh.cmd_sync_schema_props_perms(syncprops=False, commit=False)
             mh.cmd_sync_schema_props_perms(commit=False)
 
             self.assertEqual(cnx.execute('Any D WHERE X name "Personne", X description D')[0][0],