[PATCH 3 of 6 seda] [migration] Fix potentiel NoResult / MultipleRows error

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 31 17:08:45 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490963259 -7200
#      Fri Mar 31 14:27:39 2017 +0200
# Node ID 71250602be5574f1def04cdcd6d3c71106de0f55
# Parent  1269e5d31ecd511d580fedea7f1443391271edeb
[migration] Fix potentiel NoResult / MultipleRows error

We prefer a succeding migration then detecting weirdness in the database.
Error encountered while migrating the seda demo.

diff --git a/cubicweb_seda/migration/0.9.1_Any.py b/cubicweb_seda/migration/0.9.1_Any.py
--- a/cubicweb_seda/migration/0.9.1_Any.py
+++ b/cubicweb_seda/migration/0.9.1_Any.py
@@ -9,22 +9,22 @@ commit()
 sync_schema_props_perms('container')
 
 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)
+    for label in 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}).entities():
+        label.cw_set(label=new_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)
+    for label in 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}).entities():
+        label.cw_set(label=new_label)
     # don't care about migrating updated definition for now
 commit()
 
 
 sync_schema_props_perms('seda_description_level')


More information about the saem-devel mailing list