Skip to content

Commit ae4a5be

Browse files
committed
CodeRabbit review comments implementation.
1 parent f49ee8e commit ae4a5be

4 files changed

Lines changed: 30 additions & 11 deletions

File tree

api.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ paths:
8989
items:
9090
type: string
9191

92-
/topics/{topicName}:
92+
/topics/{topic_name}:
9393
get:
9494
summary: Get schema for a specific topic
9595
description: Returns the schema for a specified topic using [JSON Schema](https://json-schema.org/).
9696
parameters:
97-
- name: topicName
97+
- name: topic_name
9898
in: path
9999
required: true
100100
schema:
@@ -125,7 +125,7 @@ paths:
125125
security:
126126
- bearerAuth: []
127127
parameters:
128-
- name: topicName
128+
- name: topic_name
129129
in: path
130130
required: true
131131
schema:
@@ -179,7 +179,7 @@ paths:
179179
error:
180180
type: string
181181

182-
/stats/{topicName}:
182+
/stats/{topic_name}:
183183
post:
184184
summary: Query run/job statistics
185185
description: >
@@ -189,7 +189,7 @@ paths:
189189
security:
190190
- bearerAuth: []
191191
parameters:
192-
- name: topicName
192+
- name: topic_name
193193
in: path
194194
required: true
195195
schema:

src/handlers/handler_stats.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ def handle_request(self, event: dict[str, Any]) -> dict[str, Any]:
8888
cursor = body.get("cursor")
8989
limit: int = body.get("limit", POSTGRES_DEFAULT_LIMIT)
9090

91-
if timestamp_start is not None and not isinstance(timestamp_start, int):
91+
if timestamp_start is not None and (isinstance(timestamp_start, bool) or not isinstance(timestamp_start, int)):
9292
return build_error_response(400, "validation", "Field 'timestamp_start' must be an integer (epoch ms).")
93-
if timestamp_end is not None and not isinstance(timestamp_end, int):
93+
if timestamp_end is not None and (isinstance(timestamp_end, bool) or not isinstance(timestamp_end, int)):
9494
return build_error_response(400, "validation", "Field 'timestamp_end' must be an integer (epoch ms).")
95-
if cursor is not None and not isinstance(cursor, int):
95+
if cursor is not None and (isinstance(cursor, bool) or not isinstance(cursor, int)):
9696
return build_error_response(400, "validation", "Field 'cursor' must be an integer (internal_id).")
97-
if not isinstance(limit, int) or limit < 1:
97+
if not isinstance(limit, int) or isinstance(limit, bool) or limit < 1:
9898
return build_error_response(400, "validation", "Field 'limit' must be a positive integer.")
9999

100100
# Execute query
@@ -107,7 +107,7 @@ def handle_request(self, event: dict[str, Any]) -> dict[str, Any]:
107107
)
108108
except RuntimeError as exc:
109109
logger.exception("Stats query failed for topic %s.", topic_name)
110-
return build_error_response(500, "database", str(exc))
110+
return build_error_response(500, "database", "Stats query failed.")
111111

112112
return {
113113
"statusCode": 200,

src/writers/writer_postgres.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PsycopgError(Exception): # type: ignore
4343

4444
class WriterPostgres(Writer):
4545
"""Postgres writer for storing events in PostgreSQL database.
46-
Database credentials are loaded from AWS Secrets Manager at initialization.
46+
Database credentials are loaded lazily from AWS Secrets Manager on first use.
4747
"""
4848

4949
def __init__(self, config: dict[str, Any]) -> None:

tests/unit/handlers/test_handler_stats.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,24 @@ def test_invalid_limit_returns_400(self, handler: HandlerStats) -> None:
221221

222222
assert 400 == response["statusCode"]
223223

224+
def test_boolean_timestamp_start_returns_400(self, handler: HandlerStats) -> None:
225+
"""Test that boolean timestamp_start is rejected."""
226+
response = handler.handle_request(_make_event(body={"timestamp_start": True}))
227+
228+
assert 400 == response["statusCode"]
229+
230+
def test_boolean_cursor_returns_400(self, handler: HandlerStats) -> None:
231+
"""Test that boolean cursor is rejected."""
232+
response = handler.handle_request(_make_event(body={"cursor": False}))
233+
234+
assert 400 == response["statusCode"]
235+
236+
def test_boolean_limit_returns_400(self, handler: HandlerStats) -> None:
237+
"""Test that boolean limit is rejected."""
238+
response = handler.handle_request(_make_event(body={"limit": True}))
239+
240+
assert 400 == response["statusCode"]
241+
224242

225243
class TestHandlerStatsErrors:
226244
"""Tests for error handling."""
@@ -235,3 +253,4 @@ def test_database_error_returns_500(self, handler: HandlerStats, mock_reader: Ma
235253
body = json.loads(response["body"])
236254
assert False is body["success"]
237255
assert "database" == body["errors"][0]["type"]
256+
assert "Stats query failed." == body["errors"][0]["message"]

0 commit comments

Comments
 (0)