When Spring Modulith events are persisted in a relational database, retrieving incomplete publications via: org.springframework.modulith.events.core.EventPublicationRegistry#findIncompletePublications() returns publications whose status value is incorrect when accessed through: org.springframework.modulith.events.EventPublication#getStatus()
The issue is that getStatus() in JpaEventPublicationAdapter does not return the actual persisted status field from the database. Instead, it derives the status exclusively from the value of: org.springframework.modulith.events.jpa.JpaEventPublication#completionDate
Current implementation:
@Override
public Status getStatus() {
return publication.completionDate != null ? Status.COMPLETED : Status.PUBLISHED;
}
As a result, even when the correct status is persisted in the database (for example a failed or custom state), the getter returns either:
Status.COMPLETED
Status.PUBLISHED
depending only on whether completionDate is set. This leads to inconsistent behavior, because the actual persisted state is ignored.
Expected Behavior
JpaEventPublicationAdapter#getStatus() should return the value of the persisted status field from JpaEventPublication, rather than deriving it from completionDate.
Proposed Fix
Instead of calculating the status based on completionDate, simply return the persisted status field from JpaEventPublication.
This ensures that the value returned by getStatus() is consistent with what is actually stored in the database.
@Override
public Status getStatus() {
return publication.status;
}
When Spring Modulith events are persisted in a relational database, retrieving incomplete publications via:
org.springframework.modulith.events.core.EventPublicationRegistry#findIncompletePublications()returns publications whosestatusvalue is incorrect when accessed through:org.springframework.modulith.events.EventPublication#getStatus()The issue is that
getStatus()inJpaEventPublicationAdapterdoes not return the actual persistedstatusfield from the database. Instead, it derives the status exclusively from the value of:org.springframework.modulith.events.jpa.JpaEventPublication#completionDateCurrent implementation:
As a result, even when the correct
statusis persisted in the database (for example a failed or custom state), the getter returns either:Status.COMPLETEDStatus.PUBLISHEDdepending only on whether
completionDateis set. This leads to inconsistent behavior, because the actual persisted state is ignored.Expected Behavior
JpaEventPublicationAdapter#getStatus()should return the value of the persistedstatusfield fromJpaEventPublication, rather than deriving it fromcompletionDate.Proposed Fix
Instead of calculating the status based on
completionDate, simply return the persistedstatusfield fromJpaEventPublication.This ensures that the value returned by
getStatus()is consistent with what is actually stored in the database.