fix(outbox-store): guard against empty statuses at OoutboxStore.findOldestCreatedAt() - #98
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 forstatuses.isEmpty()in both Postgres and MySQLfindOldestCreatedAt()implementations. - Updated the
OutboxStore.findOldestCreatedAtKDoc to document the empty-input behavior. - Added a contract regression test ensuring empty
statusesreturns 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#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.