Skip to content

Commit 8431f24

Browse files
committed
fix: ci typecheck
1 parent a97f32f commit 8431f24

3 files changed

Lines changed: 41 additions & 31 deletions

File tree

src/sentinel_api/appeals.py

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any, Literal, cast, get_args
1111
from uuid import uuid4
1212

13+
from psycopg import sql
1314
from pydantic import BaseModel, ConfigDict, Field
1415

1516
from sentinel_api.logging import get_logger
@@ -461,53 +462,59 @@ def list_appeals(
461462
request_id: str | None,
462463
limit: int,
463464
) -> AdminAppealListResponse:
464-
where_conditions: list[str] = []
465+
where_conditions: list[sql.Composable] = []
465466
where_params: list[object] = []
466467
if status is not None:
467-
where_conditions.append("status = %s")
468+
where_conditions.append(sql.SQL("status = %s"))
468469
where_params.append(status)
469470
if request_id is not None:
470-
where_conditions.append("request_id = %s")
471+
where_conditions.append(sql.SQL("request_id = %s"))
471472
where_params.append(request_id)
472-
where_clause = ""
473+
where_clause = sql.SQL("")
473474
if where_conditions:
474-
where_clause = "WHERE " + " AND ".join(where_conditions)
475+
where_clause = sql.SQL(" WHERE ") + sql.SQL(" AND ").join(where_conditions)
475476

476477
with self._connection() as conn:
477478
with conn.cursor() as cur:
478479
cur.execute(
479-
f"SELECT COUNT(1) FROM appeals {where_clause}",
480+
sql.SQL("SELECT COUNT(1) FROM appeals") + where_clause,
480481
tuple(where_params),
481482
)
482483
total_row = cur.fetchone()
483484
total_count = int(total_row[0]) if total_row is not None else 0
484485
query_params = list(where_params)
485486
query_params.append(limit)
486487
cur.execute(
487-
f"""
488-
SELECT
489-
id,
490-
status,
491-
request_id,
492-
original_decision_id,
493-
original_action,
494-
original_reason_codes,
495-
original_model_version,
496-
original_lexicon_version,
497-
original_policy_version,
498-
original_pack_versions,
499-
submitted_by,
500-
reviewer_actor,
501-
resolution_code,
502-
resolution_reason_codes,
503-
created_at,
504-
updated_at,
505-
resolved_at
506-
FROM appeals
507-
{where_clause}
508-
ORDER BY created_at DESC, id DESC
509-
LIMIT %s
510-
""",
488+
sql.SQL(
489+
"""
490+
SELECT
491+
id,
492+
status,
493+
request_id,
494+
original_decision_id,
495+
original_action,
496+
original_reason_codes,
497+
original_model_version,
498+
original_lexicon_version,
499+
original_policy_version,
500+
original_pack_versions,
501+
submitted_by,
502+
reviewer_actor,
503+
resolution_code,
504+
resolution_reason_codes,
505+
created_at,
506+
updated_at,
507+
resolved_at
508+
FROM appeals
509+
"""
510+
)
511+
+ where_clause
512+
+ sql.SQL(
513+
"""
514+
ORDER BY created_at DESC, id DESC
515+
LIMIT %s
516+
"""
517+
),
511518
tuple(query_params),
512519
)
513520
items = [_appeal_from_row(row) for row in cur.fetchall()]

src/sentinel_api/partner_connectors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def fetch_signals(
196196

197197
retry_delays: list[int] = []
198198
attempts = 0
199+
last_error = "unknown error"
199200

200201
def _sleep(seconds: float) -> None:
201202
self._sleep_fn(int(seconds))

src/sentinel_api/result_cache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def get_cached_result(cache_key: str, redis_url: str) -> ModerationResponse | No
4848

4949
client = redis.Redis.from_url(redis_url, decode_responses=True)
5050
cached = client.get(cache_key)
51-
if not cached:
51+
if cached is None:
52+
return None
53+
if not isinstance(cached, str):
5254
return None
5355
return ModerationResponse.model_validate_json(cached)
5456
except Exception as exc:

0 commit comments

Comments
 (0)