[PATCH seda v2] [migration] Fix potentiel NoResult / MultipleRows error

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Apr 11 15:11:23 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 9ca36b8def1f1ac5b26a0eb3c6c39efdd6210e2a
# Parent  8477512718c88a90f79b755935e4ed384c20d19f
[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)
+    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()
 
 
 sync_schema_props_perms('seda_description_level')


More information about the saem-devel mailing list