Skip to content

Commit d0028da

Browse files
lesebclaude
andauthored
fix(storage): filter expired rows in PostgreSQL keys_in_range() (#5712)
# What does this PR do? `keys_in_range()` was missing the expiration filter that `get()` and `values_in_range()` already apply, causing it to return stale keys that would resolve to nothing via `get()`. This adds the same `(expiration IS NULL OR expiration > NOW())` predicate and `ORDER BY key` for consistency with `values_in_range()`. Closes #5699 ## Test Plan 1. Pre-commit checks pass on the changed file: ``` uv run pre-commit run --files src/ogx/core/storage/kvstore/postgres/postgres.py ``` All hooks passed. 2. Verified the query now matches the structure of `values_in_range()` (same WHERE clause, same ORDER BY). Signed-off-by: Sébastien Han <seb@redhat.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e27b39d commit d0028da

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/ogx/core/storage/kvstore/postgres/postgres.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ async def keys_in_range(self, start_key: str, end_key: str) -> list[str]:
121121

122122
cursor = self._cursor_or_raise()
123123
cursor.execute(
124-
f"SELECT key FROM {self.config.table_name} WHERE key >= %s AND key < %s",
124+
f"""
125+
SELECT key FROM {self.config.table_name}
126+
WHERE key >= %s AND key < %s
127+
AND (expiration IS NULL OR expiration > NOW())
128+
ORDER BY key
129+
""",
125130
(start_key, end_key),
126131
)
127132
return [row[0] for row in cursor.fetchall()]

0 commit comments

Comments
 (0)