Skip to content

Validate FreshRSS unread responses with Pydantic - #23

Closed
Skulldorom wants to merge 1 commit into
mainfrom
codex/add-pydantic-models-and-validation-for-freshrss
Closed

Validate FreshRSS unread responses with Pydantic#23
Skulldorom wants to merge 1 commit into
mainfrom
codex/add-pydantic-models-and-validation-for-freshrss

Conversation

@Skulldorom

Copy link
Copy Markdown
Owner

Motivation

  • Ensure the FreshRSS /reader/api/0/stream/contents payload is well-formed before processing to avoid hidden data-quality errors and crashes.
  • Apply a clear policy for malformed upstream items so callers see consistent all-or-nothing behavior instead of silent partial results.

Description

  • Add strict Pydantic models FreshRSSOrigin, FreshRSSAlternate, FreshRSSItem, and FreshRSSResponse and a validate_freshrss_response helper that uses FreshRSSResponse.model_validate to validate the top-level object and nested containers.
  • Validate published timestamps with a field validator that requires numeric, finite values and verifies datetime.fromtimestamp can represent the value.
  • Implement an all-or-nothing policy that logs validation failures and returns a sanitized HTTP 502 with detail "FreshRSS returned an invalid unread response" when the upstream response or any item is malformed.
  • Update the unread processing to consume validated model instances and add pydantic>=2.0 to pyproject.toml (and update uv.lock).

Testing

  • Ran dependency and lock checks with uv lock --check, which completed successfully.
  • Ran the test suite with uv run --frozen pytest -q, and all tests passed (27 passed).
  • Confirmed uv run pytest -q during development also passed (27 passed).

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread main.py
def validate_published_timestamp(cls, value):
if value is None:
return value
if not isfinite(value):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Skulldorom

Copy link
Copy Markdown
Owner Author

Superseded by #25 — all four PRs merged with conflict resolution and review fixes applied.

@Skulldorom Skulldorom closed this Jul 20, 2026
@Skulldorom
Skulldorom deleted the codex/add-pydantic-models-and-validation-for-freshrss branch July 20, 2026 10:01
Skulldorom added a commit that referenced this pull request Jul 20, 2026
merge: consolidate PRs #20, #21, #22, #23 with review fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant