[migration/3.18] Idempotency fixes
authorJulien Cristau <julien.cristau@logilab.fr>
Wed, 15 Jan 2014 18:19:52 +0100
changeset 9409 2f684e538174
parent 9408 f11854169654
child 9410 ce072c9aa573
[migration/3.18] Idempotency fixes Try to make partially-upgraded instances migrate properly.
misc/migration/3.18.0_Any.py
--- a/misc/migration/3.18.0_Any.py	Tue Jan 14 15:05:11 2014 +0100
+++ b/misc/migration/3.18.0_Any.py	Wed Jan 15 18:19:52 2014 +0100
@@ -15,6 +15,9 @@
     from cubicweb import Binary
     if default is None:
         return
+    if isinstance(default, Binary):
+        # partially migrated instance, try to be idempotent
+        return default
     atype = cwattr.to_entity[0].name
     if atype == 'Boolean':
         # boolean attributes with default=False were stored as ''
@@ -60,7 +63,7 @@
 
 # Set object type to "Bytes" for CWAttribute's "defaultval" attribute
 rql('SET X to_entity B WHERE X is CWAttribute, X from_entity Y, Y name "CWAttribute", '
-    'X relation_type Z, Z name "defaultval", B name "Bytes"')
+    'X relation_type Z, Z name "defaultval", B name "Bytes", NOT X to_entity B')
 
 from yams import buildobjs as ybo
 schema.add_relation_def(ybo.RelationDefinition('CWAttribute', 'defaultval', 'Bytes'))