[migration] Fix potentiel NoResult / MultipleRows error
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 31 Mar 2017 14:27:39 +0200
changeset 2593 9ca36b8def1f
parent 2592 8477512718c8
child 2610 26dbed8bb1fe
[migration] Fix potentiel NoResult / MultipleRows error We prefer a succeding migration then detecting weirdness in the database. Error encountered while migrating the seda demo.
cubicweb_seda/migration/0.9.1_Any.py
--- a/cubicweb_seda/migration/0.9.1_Any.py	Fri Mar 31 15:47:40 2017 +0200
+++ b/cubicweb_seda/migration/0.9.1_Any.py	Fri Mar 31 14:27:39 2017 +0200
@@ -11,18 +11,18 @@
 scheme = cnx.find('ConceptScheme', title=u'SEDA 2 : Status légaux').one()
 for old_label, new_label in [(u'Archive publique', u'Archives publiques'),
                              (u'Archive privée', u'Archives privées')]:
-    label = rql('Label X WHERE X label %(l)s, X label_of C, C in_scheme S, S eid %(s)s',
-                {'s': scheme.eid, 'l': old_label}).one()
-    label.cw_set(label=new_label)
+    rql('SET X label %(new_label)s WHERE X label %(old_label)s, '
+        'X label_of C, C in_scheme S, S eid %(s)s',
+        {'s': scheme.eid, 'new_label': new_label, 'old_label': old_label})
 
 commit()
 
 scheme = cnx.find('ConceptScheme', title=u'SEDA : Niveaux de description').one()
 for old_label, new_label in [(u"Dossier l'intérieur d'une série organique", u'Dossier'),
                              (u'Item', u'Pièce')]:
-    label = rql('Label X WHERE X label %(l)s, X label_of C, C in_scheme S, S eid %(s)s',
-                {'s': scheme.eid, 'l': old_label}).one()
-    label.cw_set(label=new_label)
+    rql('SET X label %(new_label)s WHERE X label %(old_label)s, '
+        'X label_of C, C in_scheme S, S eid %(s)s',
+        {'s': scheme.eid, 'new_label': new_label, 'old_label': old_label})
     # don't care about migrating updated definition for now
 commit()