A Python uuid.UUID is not converted back to java.util.UUID, so repository lookups by entity id silently find nothing
Summary
An entity id read back from Python is a Python uuid.UUID, and passing that value straight into a
repository method that takes java.util.UUID matches nothing. No error, no warning — an empty Optional
and a false, for a row that is right there.
The conversion is one-way: Java UUID → Python uuid.UUID on the way out, with nothing on the way back.
Reproducer
A @MappedEntity with a java.util.UUID id, and a CrudRepository[User, UUID] that does not override
findById or existsById — the inherited methods are enough:
repo = application_context["app.UserRepository"]
first = list(repo.findAll())[0] # the only row
python_uuid = first.id
java_uuid = JavaUUID.fromString(str(python_uuid))python_uuid=UUID('cc59c249-f74b-467f-952c-15de5109aa2b') type=<class 'uuid.UUID'>
findById(python_uuid).isPresent = False
findById(java_uuid).isPresent = True
existsById(java_uuid) = TrueSame row, same value, two outcomes. findByEmail(str) works throughout, so it is specific to the id type
rather than the repository being broken generally.
Why this is worse than it looks
It is silent. The natural thing to write is
user = service.by_id(entity.id)and it returns None — which reads as "not found" and becomes a 404. In the application this surfaced in,
DELETE /api/v1/users/{id} returned 404 for a user that GET /api/v1/users had just listed, and the only
clue was that another lookup on the same path had already been written as
UUID.fromString(str(authentication.getName())) — someone had hit this before and worked around it
locally without recognising the general case.
The workaround is to convert at every call site:
self.users.findById(UUID.fromString(str(user_id)))which is easy once known and impossible to guess, and which every application with a UUID primary key needs at every repository call.
What I think the ask is
Either coerce a Python uuid.UUID to java.util.UUID when a parameter is typed as one — the natural
counterpart to the conversion already happening on the read — or, failing that, make the mismatch loud
rather than returning an empty result.
Environment
- Micronaut Core 5.2.5, Micronaut Platform 5.1.0, GraalPy 25.4.4.1.1, GraalVM 25.4.4, macOS aarch64
- Micronaut Data JDBC against MySQL 8.4 via Test Resources
This appeared when moving from Micronaut Core 5.2.2 / GraalPy 25.3.4.1 to 5.2.5 / GraalPy 25.4.4.1.1: the same project's suite passed before and has five failures after, all of them a repository lookup by an id that came from an entity. I have not bisected which of the two upgrades introduces it, so "regression in 5.2.5" is a description of where it showed up rather than a diagnosis.
Source: micronaut-projects/micronaut-core