Commit 6cff40d5 authored by Julien Cristau's avatar Julien Cristau
Browse files

WIP try to handle constraint violations involving more than one column

Related to #10673348
parent e3f28ad6f926
Pipeline #92026 failed with stages
in 43 minutes and 13 seconds
......@@ -626,11 +626,28 @@ class IUserFriendlyCheckConstraint(IUserFriendlyError):
break
else:
assert 0
key = rschema.type + "-subject"
# use .get since a constraint may be associated to an attribute that isn't edited (e.g.
# constraint between two attributes). This should be the purpose of an api rework at some
# point, we currently rely on the fact that such constraint will provide a dedicated user
# message not relying on the `value` argument
value = self.entity.cw_edited.get(rschema.type)
msg, args = constraint.failed_message(key, value, self.entity)
rtype = rschema.type
# if the constraint involves more than one column, try to find one which was modified
if rtype not in self.entity.cw_edited:
from yams.constraints import Attribute
if constraint.type() == "BoundaryConstraint":
if (
isinstance(constraint.boundary, Attribute)
and constraint.boundary.attr in self.entity.cw_edited
):
rtype = constraint.boundary.attr
elif constraint.type() == "IntervalBoundConstraint":
if (
isinstance(constraint.minvalue, Attribute)
and constraint.minvalue.attr in self.entity.cw_edited
):
rtype = constraint.minvalue.attr
elif (
isinstance(constraint.maxvalue, Attribute)
and constraint.maxvalue.attr in self.entity.cw_edited
):
rtype = constraint.maxvalue.attr
key = rtype + "-subject"
msg, args = constraint.failed_message(key, self.entity, rtype)
raise ValidationError(self.entity.eid, {key: msg}, args)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment