You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The testing backend currently allows having attribute values that don't match the constraint of that attribute, e.g. having two different values for two variants of the same product for an attribute that has the SAME_FOR_ALL constraint.
The real commercetools API gives a nice error message like:
commercetools.exceptions.CommercetoolsError: The value '"Some Other value"' is not valid for field 'anAttributeWithASameForAllConstraint'. Allowed values are: "Some value". The value of the attribute must be the same across all variants.
It would be nice if we had similar validation in the testing backend. In quick half-pseudocode something like:
defvalidate_constrained_attribute(
variants: List[models.ProductVariantDraft], attr: ProductAttribute
):
constraint_type=attr.constraintifconstraint_type==models.AttributeConstraintEnum.SAME_FOR_ALL:
flat_attributes= [
itemforsublistin [var.attributesforvarinvariants]
foriteminsublist
]
# check if all values for the attribute across all variants are the same:values= [a.valueforainflat_attributesifa.name==attr.name]
ifnotvalues:
returnunique_values=someformofsetdependingonattributetypeiflen(unique_values) !=1:
raiseValidationError(
"Some complete error message"
)
else:
returnelifconstraint_type==models.AttributeConstraintEnum.UNIQUE:
flat_attributes= [
itemforsublistin [var.attributesforvarinvariants]
foriteminsublist
]
# check if all values for the attribute across all variants are different:values= [a.valueforainflat_attributesifa.name==attr.name]
ifnotvalues:
returnunique_values=someformofsetdependingonattributetypeiflen(unique_values) !=len(values):
raiseValidationError(
"Some complete error message"
)
else:
returnelifconstraint_type==models.AttributeConstraintEnum.COMBINATION_UNIQUE:
# this will probably be a little more convolutedelse:
raiseValidationError(
"Could not recognize constrained attribute type: %s", attr.constraint
)
The text was updated successfully, but these errors were encountered:
The testing backend currently allows having attribute values that don't match the constraint of that attribute, e.g. having two different values for two variants of the same product for an attribute that has the
SAME_FOR_ALL
constraint.The real commercetools API gives a nice error message like:
It would be nice if we had similar validation in the testing backend. In quick half-pseudocode something like:
The text was updated successfully, but these errors were encountered: