Skip to content

Ignore unknown API fields when building ListEntry#112

Open
SAY-5 wants to merge 1 commit into
glensc:mainfrom
SAY-5:fix-listentry-unknown-fields
Open

Ignore unknown API fields when building ListEntry#112
SAY-5 wants to merge 1 commit into
glensc:mainfrom
SAY-5:fix-listentry-unknown-fields

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 26, 2026

Copy link
Copy Markdown

Trakt's list-items endpoint now returns a my_rating field on each item. ListEntry is a frozen dataclass with a fixed set of fields, so ListEntry(**item, data=data) raises TypeError: ListEntry.__init__() got an unexpected keyword argument 'my_rating', which breaks loading the whole list.

This filters item down to the fields ListEntry actually declares before constructing it, so unknown fields the API adds are ignored rather than crashing. Added a regression test in tests/test_users.py.

Fixes #111

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 68793b70-acad-4532-a416-669340742e88

📥 Commits

Reviewing files that changed from the base of the PR and between d3df38f and 622d1e9.

📒 Files selected for processing (2)
  • tests/test_users.py
  • trakt/users.py

Walkthrough

PublicList._process_items now filters incoming list-item payloads to declared ListEntry fields before constructing entries. A new test covers an item with an extra field and confirms parsing still yields the expected id and title.

Changes

ListEntry payload filtering

Layer / File(s) Summary
Filter unknown list-item fields
trakt/users.py, tests/test_users.py
PublicList._process_items now drops undeclared item keys before building ListEntry, and the test suite checks that an item with an extra field still parses correctly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny hopped by with a twitchy nose,
And found the extra fields in tidy rows.
"Snip-snip," said I, "keep the list so neat!"
Now ListEntry lands on its fluffy feet.
🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main fix: ignoring unknown API fields while constructing ListEntry.
Description check ✅ Passed The description accurately describes the bug, the filtering fix, and the added regression test.
Linked Issues check ✅ Passed The code addresses #111 by filtering API items to ListEntry fields, preventing unexpected my_rating from crashing list loading.
Out of Scope Changes check ✅ Passed The changes stay focused on the ListEntry fix and regression test, with no unrelated additions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

TypeError: ListEntry.__init__() got an unexpected keyword argument 'my_rating'

1 participant