-
Notifications
You must be signed in to change notification settings - Fork 33
Schema validation coerces missing numbers to 0 #2679
Copy link
Copy link
Open
Labels
area/validationrelated to form validation rules/messagesrelated to form validation rules/messageskind/bugSomething isn't workingSomething isn't workingorg/brgIssues relevant for Brønnøysundregistrene.Issues relevant for Brønnøysundregistrene.status/for-considerationIssues that will be considered for future deliveriesIssues that will be considered for future deliveries
Metadata
Metadata
Assignees
Labels
area/validationrelated to form validation rules/messagesrelated to form validation rules/messageskind/bugSomething isn't workingSomething isn't workingorg/brgIssues relevant for Brønnøysundregistrene.Issues relevant for Brønnøysundregistrene.status/for-considerationIssues that will be considered for future deliveriesIssues that will be considered for future deliveries
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
No status
Status
No status
Description of the bug
Slack: https://altinn.slack.com/archives/C02EJ9HKQA3/p1730302631757679
We use
coerceTypes: truein AJV, this will convert values to the "correct" type before validating. This can be useful if e.g. a number is stored as a string, so that"12"will be treated as12and will not fail thetype: numbervalidation. A less fortunate side-effect of this is that it will also coercenullto something that is valid for each type. For numbers,null->0, which can cause validations to appear when they should not. We usenullto say that a value is missing, and this should not give an error unless it isrequired.coerceTypes: truewas probably necessary previously when we stored all of the form data as strings. This is no longer the case, so we may be able to get rid of this option now. It could easily break things however, so we cannot just remove this without testing extensively in existing apps.One possible solution is removing
nullvalues from the datamodel before running the schema validation. It does not seem like we can fix this by messing with other AJV options (useDefaults: 'empty'did not change things)Steps To Reproduce
.
Additional Information
No response