Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: ci

on:
push:
branches: ["**"]
pull_request:
workflow_dispatch:

jobs:
test:
Expand Down
67 changes: 37 additions & 30 deletions src/sentinel_api/appeals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any, Literal, cast, get_args
from uuid import uuid4

from psycopg import sql
from pydantic import BaseModel, ConfigDict, Field

from sentinel_api.logging import get_logger
Expand Down Expand Up @@ -461,53 +462,59 @@ def list_appeals(
request_id: str | None,
limit: int,
) -> AdminAppealListResponse:
where_conditions: list[str] = []
where_conditions: list[sql.Composable] = []
where_params: list[object] = []
if status is not None:
where_conditions.append("status = %s")
where_conditions.append(sql.SQL("status = %s"))
where_params.append(status)
if request_id is not None:
where_conditions.append("request_id = %s")
where_conditions.append(sql.SQL("request_id = %s"))
where_params.append(request_id)
where_clause = ""
where_clause = sql.SQL("")
if where_conditions:
where_clause = "WHERE " + " AND ".join(where_conditions)
where_clause = sql.SQL(" WHERE ") + sql.SQL(" AND ").join(where_conditions)

with self._connection() as conn:
with conn.cursor() as cur:
cur.execute(
f"SELECT COUNT(1) FROM appeals {where_clause}",
sql.SQL("SELECT COUNT(1) FROM appeals") + where_clause,
tuple(where_params),
)
total_row = cur.fetchone()
total_count = int(total_row[0]) if total_row is not None else 0
query_params = list(where_params)
query_params.append(limit)
cur.execute(
f"""
SELECT
id,
status,
request_id,
original_decision_id,
original_action,
original_reason_codes,
original_model_version,
original_lexicon_version,
original_policy_version,
original_pack_versions,
submitted_by,
reviewer_actor,
resolution_code,
resolution_reason_codes,
created_at,
updated_at,
resolved_at
FROM appeals
{where_clause}
ORDER BY created_at DESC, id DESC
LIMIT %s
""",
sql.SQL(
"""
SELECT
id,
status,
request_id,
original_decision_id,
original_action,
original_reason_codes,
original_model_version,
original_lexicon_version,
original_policy_version,
original_pack_versions,
submitted_by,
reviewer_actor,
resolution_code,
resolution_reason_codes,
created_at,
updated_at,
resolved_at
FROM appeals
"""
)
+ where_clause
+ sql.SQL(
"""
ORDER BY created_at DESC, id DESC
LIMIT %s
"""
),
tuple(query_params),
)
items = [_appeal_from_row(row) for row in cur.fetchall()]
Expand Down
1 change: 1 addition & 0 deletions src/sentinel_api/partner_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def fetch_signals(

retry_delays: list[int] = []
attempts = 0
last_error = "unknown error"

def _sleep(seconds: float) -> None:
self._sleep_fn(int(seconds))
Expand Down
4 changes: 3 additions & 1 deletion src/sentinel_api/result_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def get_cached_result(cache_key: str, redis_url: str) -> ModerationResponse | No

client = redis.Redis.from_url(redis_url, decode_responses=True)
cached = client.get(cache_key)
if not cached:
if cached is None:
return None
if not isinstance(cached, str):
return None
return ModerationResponse.model_validate_json(cached)
except Exception as exc:
Expand Down