-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: listrr response being treated as a dict #979
base: main
Are you sure you want to change the base?
Conversation
Warning Rate limit exceeded@davidemarcoli has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 41 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe pull request modifies the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/program/apis/listrr_api.py (1)
58-59
: Simplify attribute access for SimpleNamespace objects.Since the response is parsed as
SimpleNamespace
(configured inListrrRequestHandler
), you can use direct attribute access with fallback values using theor
operator for better readability.- total_pages = getattr(data, "pages", 1) - for item in getattr(data, "items", []): + total_pages = getattr(data, 'pages') or 1 + for item in getattr(data, 'items') or []:
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/program/apis/listrr_api.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/program/apis/listrr_api.py
60-60: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
63-63: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
64-64: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
🔇 Additional comments (1)
src/program/apis/listrr_api.py (1)
58-64
: Add tests for Listrr response handling.The changes modify how API responses are handled, but tests haven't been added according to the PR checklist. Please add tests to verify:
- Handling of responses with missing attributes
- Proper fallback to default values
- TMDb ID fallback scenario
Would you like me to help generate test cases for these scenarios?
🧰 Tools
🪛 Ruff (0.8.2)
60-60: Do not call
getattr
with a constant attribute value. It is not any safer than normal property access.Replace
getattr
with attribute access(B009)
63-63: Do not call
getattr
with a constant attribute value. It is not any safer than normal property access.Replace
getattr
with attribute access(B009)
64-64: Do not call
getattr
with a constant attribute value. It is not any safer than normal property access.Replace
getattr
with attribute access(B009)
src/program/apis/listrr_api.py
Outdated
imdb_id = getattr(item,"imDbId") | ||
if imdb_id: | ||
unique_ids.add(imdb_id) | ||
elif content_type == "Movies" and item.get("tmDbId"): | ||
imdb_id = self.trakt_api.get_imdbid_from_tmdb(item["tmDbId"]) | ||
elif content_type == "Movies" and getattr(item, "tmDbId"): | ||
imdb_id = self.trakt_api.get_imdbid_from_tmdb(getattr(item, "tmDbId")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use direct attribute access with proper error handling.
Since we're working with SimpleNamespace objects, we should use direct attribute access with proper error handling to catch potential AttributeError exceptions.
- imdb_id = getattr(item,"imDbId")
- if imdb_id:
- unique_ids.add(imdb_id)
- elif content_type == "Movies" and getattr(item, "tmDbId"):
- imdb_id = self.trakt_api.get_imdbid_from_tmdb(getattr(item, "tmDbId"))
+ try:
+ if item.imDbId:
+ unique_ids.add(item.imDbId)
+ elif content_type == "Movies" and item.tmDbId:
+ imdb_id = self.trakt_api.get_imdbid_from_tmdb(item.tmDbId)
+ if imdb_id:
+ unique_ids.add(imdb_id)
+ except AttributeError:
+ # Skip items that don't have the expected attributes
+ continue
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
imdb_id = getattr(item,"imDbId") | |
if imdb_id: | |
unique_ids.add(imdb_id) | |
elif content_type == "Movies" and item.get("tmDbId"): | |
imdb_id = self.trakt_api.get_imdbid_from_tmdb(item["tmDbId"]) | |
elif content_type == "Movies" and getattr(item, "tmDbId"): | |
imdb_id = self.trakt_api.get_imdbid_from_tmdb(getattr(item, "tmDbId")) | |
try: | |
if item.imDbId: | |
unique_ids.add(item.imDbId) | |
elif content_type == "Movies" and item.tmDbId: | |
imdb_id = self.trakt_api.get_imdbid_from_tmdb(item.tmDbId) | |
if imdb_id: | |
unique_ids.add(imdb_id) | |
except AttributeError: | |
# Skip items that don't have the expected attributes | |
continue |
🧰 Tools
🪛 Ruff (0.8.2)
60-60: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
63-63: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
64-64: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidemarcoli its got a point :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take note of the code rabbit suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/program/apis/listrr_api.py
(1 hunks)
🔇 Additional comments (2)
src/program/apis/listrr_api.py (2)
61-77
: Well-structured error handling and logging!The implementation correctly:
- Uses proper error handling for attribute access
- Includes clear fallback logic for TMDb IDs
- Adds informative warning logs for missing IDs and duplicates
42-42
: Add tests for the updated Listrr response handling.The PR checklist indicates that tests haven't been added yet. Please add tests to verify:
- Successful IMDb ID retrieval
- Fallback to TMDb ID
- Error handling for missing attributes
- Duplicate handling
Would you like me to help generate test cases for these scenarios?
src/program/apis/listrr_api.py
Outdated
total_pages = getattr(data, "pages", 1) | ||
for item in getattr(data, "items", []): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use direct attribute access instead of getattr
.
Using getattr
with constant attribute values is not safer than direct attribute access. The static analysis tool also flags this as B009.
Apply this diff to use direct attribute access:
- total_pages = getattr(data, "pages", 1)
- for item in getattr(data, "items", []):
+ total_pages = data.pages if hasattr(data, "pages") else 1
+ for item in data.items if hasattr(data, "items") else []:
Committable suggestion skipped: line range outside the PR's diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/program/apis/listrr_api.py (1)
61-67
: Consider restructuring for better readability.While the logic is correct, the nested conditions and short-circuit evaluation could be more readable.
Consider this alternative structure:
- try: - imdb_id = item.imDbId or ( - self.trakt_api.get_imdbid_from_tmdb(item.tmDbId) - if content_type == "Movies" and item.tmDbId - else None - ) + try: + imdb_id = item.imDbId + if not imdb_id and content_type == "Movies": + if hasattr(item, "tmDbId") and item.tmDbId: + imdb_id = self.trakt_api.get_imdbid_from_tmdb(item.tmDbId)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/program/apis/listrr_api.py
(1 hunks)
🔇 Additional comments (3)
src/program/apis/listrr_api.py (3)
58-59
: LGTM! Safe attribute access implementation.The changes correctly implement direct attribute access with proper fallback handling using
hasattr
checks.
68-77
: LGTM! Comprehensive error handling with informative logs.The implementation properly handles:
- Null IMDb IDs
- Duplicate entries with warning logs
- Missing ID attributes with descriptive error messages
42-42
: Add tests for the updated data parsing logic.The PR checklist indicates that tests haven't been added. Since these changes involve critical data parsing logic, please add tests to verify:
- Handling of missing attributes
- TMDb ID fallback for movies
- Duplicate detection
Would you like me to help generate test cases for these scenarios?
if not imdb_id: | ||
continue | ||
if imdb_id in unique_ids: | ||
logger.warning(f"Skipping duplicate item {imdb_id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove this log message as its going to hit this quite a lot anyways by default?
Pull Request Check List
Resolves: #975, Resolves #959
Description:
Summary by CodeRabbit
Summary by CodeRabbit