Altinn / Altinn/app-lib-dotnet

Validate prefill.json

Open
#1,375 1 comment 0 reactions 0 assignees View on GitHub
status/triage
Dominant language
C#
Stars
8
Forks
27
Avg merge
1h 21m
Merged PRs (30d)
7

Description

A support case reporting issues with instantiating an application in TT02 and not locally was reported.

Investigation into the application showed that the error, which was a generic 500 error;

```
Message: Request failed with status code 500
Request: POST 'https://hb.apps.tt02.altinn.no/hb/prosjekt-25-laan-privat/instances?instanceOwnerPartyId=51564076&language=nb'
Response: Instantiation of data elements failed for instance 51564076/add8b18b-55e6-4360-a7e1-3a2c87bee02c for party 51564076
```

was caused by a mismatch in the datamodel type and the type of the prefill data.
The app had an `int?` field, prefill was ´string´.

This worked in the case of "123", [as the mapping is lenient](https://github.com/Altinn/app-lib-dotnet/blob/de4c34f86777decd951ae16787f69c53bc770649/src/Altinn.App.Core/Implementation/PrefillSI.cs#L245-L246), but not in the case of empty string `""`

Possible solutions:

Startup validation of `prefill.json`:
If mismatch between types, give a build warning.

Special case for empty string:
`""` leads to
`0` for `int` and
`null` for `int?`

Contributor guide

Open the contributing guide

Research direction

Start by reading the prefill mapping logic in src/Altinn.App.Core/Implementation/PrefillSI.cs, especially the linked lines around type conversion. Clarify whether the intended fix is startup validation, special handling for empty strings, or both; the issue is done when the reported int/int? and string mismatch no longer produces the generic instantiation failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.