Validate FreshRSS unread responses with Pydantic - #23
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5743a77755
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def validate_published_timestamp(cls, value): | ||
| if value is None: | ||
| return value | ||
| if not isfinite(value): |
There was a problem hiding this comment.
Catch overflow before checking timestamp finiteness
When published is a sufficiently large JSON integer (for example, a few hundred digits), math.isfinite(value) raises OverflowError while converting it to a float. Because this occurs before the guarded datetime.fromtimestamp call and Pydantic does not wrap OverflowError from a field validator as ValidationError, the endpoint returns an internal 500 instead of the sanitized 502 promised for malformed FreshRSS responses.
Useful? React with 👍 / 👎.
|
Superseded by #25 — all four PRs merged with conflict resolution and review fixes applied. |
Motivation
/reader/api/0/stream/contentspayload is well-formed before processing to avoid hidden data-quality errors and crashes.Description
FreshRSSOrigin,FreshRSSAlternate,FreshRSSItem, andFreshRSSResponseand avalidate_freshrss_responsehelper that usesFreshRSSResponse.model_validateto validate the top-level object and nested containers.publishedtimestamps with a field validator that requires numeric, finite values and verifiesdatetime.fromtimestampcan represent the value.HTTP 502with detail"FreshRSS returned an invalid unread response"when the upstream response or any item is malformed.pydantic>=2.0topyproject.toml(and updateuv.lock).Testing
uv lock --check, which completed successfully.uv run --frozen pytest -q, and all tests passed (27 passed).uv run pytest -qduring development also passed (27 passed).Codex Task