Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema validation coerces missing numbers to 0 #2679

Open
bjosttveit opened this issue Nov 1, 2024 · 1 comment
Open

Schema validation coerces missing numbers to 0 #2679

bjosttveit opened this issue Nov 1, 2024 · 1 comment
Labels
kind/bug Something isn't working

Comments

@bjosttveit
Copy link
Member

Description of the bug

Slack: https://altinn.slack.com/archives/C02EJ9HKQA3/p1730302631757679

We use coerceTypes: true in 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 as 12 and will not fail the type: number validation. A less fortunate side-effect of this is that it will also coerce null to something that is valid for each type. For numbers, null -> 0, which can cause validations to appear when they should not. We use null to say that a value is missing, and this should not give an error unless it is required.

coerceTypes: true was 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 null values 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

@bjosttveit bjosttveit added the kind/bug Something isn't working label Nov 1, 2024
@Hedda-ro
Copy link

Mulig relatert, viktig bug hos Årsregnskap nå:

Som beskrevet i Slack nylig: vi har en rekke Input-felter i Grid med maksbegrensning på antall siffer definert i en .xsd-fil (totalDigits). Dersom man overgår maksbegrensningen i et slikt felt og deretter sletter hele verdien (altså ctrl+A+del), så henger feilmeldingen igjen (som illustrert). Dette gjelder kun når man sletter hele verdien (ctrl+A+del). Det gjelder ikke når man sletter et og et siffer, da forsvinner meldingen av seg selv når maksbegrensningen ikke er nådd lenger.

Image

Image

Feltet som vist ovenfor er ikke obligatorisk. For å bli kvitt feilmeldingen må man refreshe siden...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
Status: No status
Status: No status
Development

No branches or pull requests

2 participants