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

GET instances fails when query includes corrupt jsonb instances #610

Open
hggutvik opened this issue Jan 22, 2025 · 0 comments
Open

GET instances fails when query includes corrupt jsonb instances #610

hggutvik opened this issue Jan 22, 2025 · 0 comments
Labels
kind/bug Something isn't working

Comments

@hggutvik
Copy link
Contributor

hggutvik commented Jan 22, 2025

Description of the bug

For a few apps in TT02 and Production, GET instances?appId={app-with-some-corrupt-instances} results in 400 Bad Request with message "The JSON value could not be converted to Altinn.Platform.Storage.Interface.Models.Instance. Path: $ | LineNumber: 0 | BytePositionInLine: 1."
Link to Slack post that made us aware of this - includes discussion on possible causes.

When these few corrupt instances are included in a query for instances, the deserialization from JSON to .NET class fails. Currently, this breaks the whole query, thus making the requested data unavailable.

The corrupt instances can be found in the DB table storage.instances of tt02 and prod, as rows where the instance jsonb element has the structure of
[ { "id": "..", etc. }, "2024-..." ]
instead of
{ "id": "...", etc. } .
You can query the instances by running select * from storage.instances where jsonb_typeof(instance) ='array' order by created asc

Steps To Reproduce

Run GET storage/api/v1/instances?appId=krt/krt-1064a-1 or GET storage/api/v1/instances?appId=ttd/frontend-test in TT02

Scope

Correct the corrupt instances, so that the jsonb data have the expected structure.

While we also want to change the functionality of filtering out such broken data in this endpoint, thus allowing normal instances to be returned with 200 OK, this functional change is to be addressed in a separate issue (#604)

Proposed solution

Run a script that updates the instances in question, row by row. Start with AT envs (if we can find corrupt instances there as well), then TT envs, and Production lastly

Additional information

There are 6 known instances in AT23, 30 in TT02, and 8 in Production.

Relevant resource for updating jsonb data: https://www.postgresql.org/docs/current/datatype-json.html

@hggutvik hggutvik added the kind/bug Something isn't working label Jan 22, 2025
@hggutvik hggutvik changed the title Corrupt instances are breaking GET instances, making related data unavailable GET instances fails when query includes corrupt jsonb instances Jan 22, 2025
@hggutvik hggutvik assigned hggutvik and unassigned hggutvik Jan 29, 2025
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
None yet
Development

No branches or pull requests

1 participant