Skip to content

JPA Map storage doesn't downgrade entityVersion when modifying a row written with a future entityVersion #9716

@ahus1

Description

@ahus1

Describe the bug

When the Map JPA store reads data from a row, it accepts data that is written by another Keycloak version with entityVersion N+1. Thereby it ignores new fields written by a later version during JSON de-serialization.

When it then writes the data back to the database, it uses its JSON serializer and writes the data in the format of its own JSON schema to the row. Therefore, it should downgrade the entityVersion to N as well, so that is future version of Keycloak can again migrate the data to a later entity version.

Version

17.0.0-SNAPSHOT

Expected behavior

  • when data is written to the row, the entity version is always the SUPPORTED_VERSION_* of the implementation

Actual behavior

  • when data is written to the row, the entity version is kept "as is", thereby leaving the N+1 version in the row. This prevents a future migration of the JSON and is inconsistent with the data in the JSON column.

How to Reproduce?

Manual testing with the database

Anything else?

There is a discussion on this topic here: #9640

Possible refactoring: Rework repetitive calls to checkEntityVersionForUpdate() in JpaClientEntity to a method annotated with @PreUpdate and @PrePersist, so that is called whenever a SQL insert or update is triggered.

This would prevent missing an update to the entity version in cases where Hibernate triggers an update to the database.

Metadata

Metadata

Assignees

Labels

area/storageIndicates an issue that touches storage (change in data layout or data manipulation)kind/bugCategorizes a PR related to a bug

Type

No type

Projects

Status

✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions