Skip to content

fix(outbox-store): guard against empty statuses at OoutboxStore.findOldestCreatedAt() - #98

Merged
rawo merged 1 commit into
mainfrom
bugfix/issue-60
Jul 31, 2026
Merged

fix(outbox-store): guard against empty statuses at OoutboxStore.findOldestCreatedAt()#98
rawo merged 1 commit into
mainfrom
bugfix/issue-60

Conversation

@rawo

@rawo rawo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

#60

Fixed issue #60 on branch bugfix/issue-60: findOldestCreatedAt built WHERE status IN () when passed an empty statuses set — a SQL syntax error on both Postgres and MySQL.

Fix: added if (statuses.isEmpty()) return emptyMap() as an early guard in both PostgresOutboxStore.findOldestCreatedAt and MysqlOutboxStore.findOldestCreatedAt. This is the semantically correct result (not an error) — an empty statuses set trivially matches nothing, consistent with the existing "statuses with no entries are omitted from the result" contract.

Docs: updated the OutboxStore.findOldestCreatedAt KDoc to state that an empty statuses set returns an empty map.

Tests: added one regression test to the shared outboxStoreContractTests suite (okapi-integration-tests), which runs automatically against both real Postgres and MySQL via Testcontainers — no per-adapter duplication needed.

Verified against a regression: reverted just the two main-code fixes via git stash, reran the suite — both new tests failed with real SQLSyntaxErrorException/PSQLException as predicted, all 20 other tests still passed. Restored the fix; full run is green again (22/22).

ktlintCheck clean across okapi-postgres, okapi-mysql, okapi-core, okapi-integration-tests.

Copilot AI review requested due to automatic review settings July 31, 2026 09:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a SQL syntax error in the JDBC outbox-store adapters when findOldestCreatedAt() is called with an empty statuses set (previously generating WHERE status IN ()). This aligns runtime behavior with the contract that “no matching statuses” yields no results.

Changes:

  • Added an early return emptyMap() guard for statuses.isEmpty() in both Postgres and MySQL findOldestCreatedAt() implementations.
  • Updated the OutboxStore.findOldestCreatedAt KDoc to document the empty-input behavior.
  • Added a contract regression test ensuring empty statuses returns an empty map (and does not error).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
okapi-postgres/src/main/kotlin/com/softwaremill/okapi/postgres/PostgresOutboxStore.kt Prevents generating invalid IN () SQL by short-circuiting on empty statuses.
okapi-mysql/src/main/kotlin/com/softwaremill/okapi/mysql/MysqlOutboxStore.kt Prevents generating invalid IN () SQL by short-circuiting on empty statuses.
okapi-integration-tests/src/test/kotlin/com/softwaremill/okapi/test/store/OutboxStoreContractTests.kt Adds regression coverage for empty statuses input across adapters.
okapi-core/src/main/kotlin/com/softwaremill/okapi/core/OutboxStore.kt Documents that empty statuses returns an empty map.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rawo
rawo merged commit b1d8d78 into main Jul 31, 2026
9 checks passed
@rawo
rawo deleted the bugfix/issue-60 branch July 31, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants