Skip to content

JpaEventPublicationAdapter returns incorrect status when getStatus() is called #1683

@andrijailic

Description

@andrijailic

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;
}

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions