# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1455210572 -3600
# Thu Feb 11 18:09:32 2016 +0100
# Node ID d799daab4c9fb6de10b8d3479ae8cb745029b45c
# Parent a4d465a3e77d07cf6a79c121c10b2d6484cd7468
WIP try to handle constraint violations involving more than one column
Related to #10673348
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1455210572 -3600
# Thu Feb 11 18:09:32 2016 +0100
# Node ID d799daab4c9fb6de10b8d3479ae8cb745029b45c
# Parent a4d465a3e77d07cf6a79c121c10b2d6484cd7468
WIP try to handle constraint violations involving more than one column
Related to #10673348
@@ -585,13 +585,20 @@
1 else: 2 continue 3 break 4 else: 5 assert 0 6 - key = rschema.type + '-subject' 7 - # use .get since a constraint may be associated to an attribute that isn't edited (e.g. 8 - # constraint between two attributes). This should be the purpose of an api rework at some 9 - # point, we currently rely on the fact that such constraint will provide a dedicated user 10 - # message not relying on the `value` argument 11 - value = self.entity.cw_edited.get(rschema.type) 12 - msg, args = constraint.failed_message(key, value, self.entity) 13 + rtype = rschema.type 14 + # if the constraint involves more than one column, try to find one which was modified 15 + if rtype not in self.entity.cw_edited: 16 + from yams.constraints import Attribute 17 + if constraint.type() == 'BoundaryConstraint': 18 + if isinstance(constraint.boundary, Attribute) and constraint.boundary.attr in self.entity.cw_edited: 19 + rtype = constraint.boundary.attr 20 + elif constraint.type() == 'IntervalBoundConstraint': 21 + if isinstance(constraint.minvalue, Attribute) and constraint.minvalue.attr in self.entity.cw_edited: 22 + rtype = constraint.minvalue.attr 23 + elif isinstance(constraint.maxvalue, Attribute) and constraint.maxvalue.attr in self.entity.cw_edited: 24 + rtype = constraint.maxvalue.attr 25 + key = rtype + '-subject' 26 + msg, args = constraint.failed_message(key, self.entity, rtype) 27 raise ValidationError(self.entity.eid, {key: msg}, args)