Skip to content

Read a JSON Feed item's modification date from the spec field - #614

Open
rahul05ranjan wants to merge 1 commit into
kurtmckee:mainfrom
rahul05ranjan:fix/jsonfeed-date-modified
Open

rahul05ranjan wants to merge 1 commit into
kurtmckee:mainfrom
rahul05ranjan:fix/jsonfeed-date-modified

Conversation

@rahul05ranjan

Copy link
Copy Markdown

The bug

The JSON Feed parser guards on a nonstandard date_updated key while reading the spec's date_modified field:

if "date_updated" in e:
    entry["updated"] = e["date_modified"]
    entry["updated_parsed"] = _parse_date(e["date_modified"])

JSON Feed's spec defines date_published and date_modified — date_updated is not a spec field. So an item carrying only date_modified never sets updated, and through the issue-#310 compatibility fallback, consumers then see the published date as updated — silently serving a stale timestamp:

d = feedparser.parse('{"version": "https://jsonfeed.org/version/1.1", "items": [{"id": "1", "date_published": "2026-11-01T10:00:00Z", "date_modified": "2026-11-08T19:00:00Z"}]}')
d.entries[0].updated   # '2026-11-01T10:00:00Z' — the published date, not the 11-08 modification date

(Also: a feed that used the old nonstandard date_updated spelling alone hit a KeyError on date_modified instead of parsing.)

The fix

Accept both spellings, preferring the spec field: date_modified when present, else the legacy date_updated.

Verification

  • New fixture-driven cases in tests/json/: date_modified.json pins that a spec-compliant item's updated is the modification date and updated_parsed matches (while published stays intact), and date_updated_only.json pins that the legacy spelling alone no longer raises. Both fail on current main (updated falls back to the published date, triggering the [Bug] SSLCertVerificationError for URL with valid certificate. #310 deprecation warning), both pass with this change.
  • Full suite minus test_ill_formed.py/test_well_formed.py (they require the responses HTTP-mocking package, unavailable here): 841 passed / 48 failed with the fix vs 839/50 on unmodified main — the delta is exactly the two new fixtures flipping, and the 48 failures are the same test_encoding.py::test_http_encoding_file cases that need real HTTP mocking and fail identically on main on this machine (system Python 3.13.5, run from a checkout without installing).
  • Scriv fragment changelog.d/_6-rahul05ranjan-jsonfeed-date-modified.rst added.

The JSON Feed parser guarded on a nonstandard date_updated key while
reading the spec's date_modified field, so an item carrying only
date_modified (the spec's only spelling) never set updated — and
consumers saw the published date as updated through the issue-310
fallback. Accept both spellings, preferring the spec field.

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant