# HG changeset patch # User Sylvain Thénault # Date 1379933232 -7200 # Node ID 653f1d4a1101ecbb1a78ba56a04acb1c6082a887 # Parent 4b81252fccddba35d48f0029042a361d51a857fd [repository] properly use IUserFriendlyError when UniqueTogetherError is raised during entity update. Closes #3096638 diff -r 4b81252fccdd -r 653f1d4a1101 i18n/de.po --- a/i18n/de.po Wed Aug 28 12:08:31 2013 +0200 +++ b/i18n/de.po Mon Sep 23 12:47:12 2013 +0200 @@ -4534,10 +4534,6 @@ msgid "view_index" msgstr "Index-Seite" -#, python-format -msgid "violates unique_together constraints (%s)" -msgstr "Verletzung der unique_together-Einschränkung (%s)" - msgid "visible" msgstr "sichtbar" diff -r 4b81252fccdd -r 653f1d4a1101 i18n/en.po --- a/i18n/en.po Wed Aug 28 12:08:31 2013 +0200 +++ b/i18n/en.po Mon Sep 23 12:47:12 2013 +0200 @@ -4423,10 +4423,6 @@ msgid "view_index" msgstr "index" -#, python-format -msgid "violates unique_together constraints (%s)" -msgstr "violates unique_together constraints (%s)" - msgid "visible" msgstr "" diff -r 4b81252fccdd -r 653f1d4a1101 i18n/es.po --- a/i18n/es.po Wed Aug 28 12:08:31 2013 +0200 +++ b/i18n/es.po Mon Sep 23 12:47:12 2013 +0200 @@ -4582,10 +4582,6 @@ msgid "view_index" msgstr "Inicio" -#, python-format -msgid "violates unique_together constraints (%s)" -msgstr "viola el principio (o restricción) de singularidad (%s)" - msgid "visible" msgstr "Visible" diff -r 4b81252fccdd -r 653f1d4a1101 i18n/fr.po --- a/i18n/fr.po Wed Aug 28 12:08:31 2013 +0200 +++ b/i18n/fr.po Mon Sep 23 12:47:12 2013 +0200 @@ -4599,10 +4599,6 @@ msgid "view_index" msgstr "accueil" -#, python-format -msgid "violates unique_together constraints (%s)" -msgstr "violation de contrainte unique_together (%s)" - msgid "visible" msgstr "visible" diff -r 4b81252fccdd -r 653f1d4a1101 server/repository.py --- a/server/repository.py Wed Aug 28 12:08:31 2013 +0200 +++ b/server/repository.py Mon Sep 23 12:47:12 2013 +0200 @@ -1436,11 +1436,9 @@ source.update_entity(session, entity) edited.saved = True except UniqueTogetherError as exc: - etype, rtypes = exc.args - problems = {} - for col in rtypes: - problems[col] = session._('violates unique_together constraints (%s)') % (','.join(rtypes)) - raise ValidationError(entity.eid, problems) + userhdlr = session.vreg['adapters'].select( + 'IUserFriendlyError', session, entity=entity, exc=exc) + userhdlr.raise_user_exception() self.system_source.update_info(session, entity, need_fti_update) if source.should_call_hooks: if not only_inline_rels: diff -r 4b81252fccdd -r 653f1d4a1101 server/test/unittest_repository.py --- a/server/test/unittest_repository.py Wed Aug 28 12:08:31 2013 +0200 +++ b/server/test/unittest_repository.py Mon Sep 23 12:47:12 2013 +0200 @@ -558,6 +558,30 @@ req.create_entity('Affaire', ref=u'AFF02') req.execute('SET A duration 10 WHERE A is Affaire') + + def test_user_friendly_error(self): + from cubicweb.entities.adapters import IUserFriendlyUniqueTogether + class MyIUserFriendlyUniqueTogether(IUserFriendlyUniqueTogether): + __select__ = IUserFriendlyUniqueTogether.__select__ & is_instance('Societe') + def raise_user_exception(self): + raise ValidationError(self.entity.eid, {'hip': 'hop'}) + + with self.temporary_appobjects(MyIUserFriendlyUniqueTogether): + req = self.request() + s = req.create_entity('Societe', nom=u'Logilab', type=u'ssll', cp=u'75013') + self.commit() + with self.assertRaises(ValidationError) as cm: + req.create_entity('Societe', nom=u'Logilab', type=u'ssll', cp=u'75013') + self.assertEqual(cm.exception.errors, {'hip': 'hop'}) + self.rollback() + req.create_entity('Societe', nom=u'Logilab', type=u'ssll', cp=u'31400') + with self.assertRaises(ValidationError) as cm: + s.cw_set(cp=u'31400') + self.assertEqual(cm.exception.entity, s.eid) + self.assertEqual(cm.exception.errors, {'hip': 'hop'}) + self.rollback() + + class SchemaDeserialTC(CubicWebTC): appid = 'data-schemaserial'