-
-
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?
Changes from 1 commit
9a7c993
7516aef
e3b048d
f227696
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -55,13 +55,13 @@ def get_items_from_Listrr(self, content_type, content_lists) -> list[MediaItem] | |||||||||||||||||||||||||||||||||||
url = f"api/List/{content_type}/{list_id}/ReleaseDate/Descending/{page}" | ||||||||||||||||||||||||||||||||||||
response = self.request_handler.execute(HttpMethod.GET, url) | ||||||||||||||||||||||||||||||||||||
data = response.data | ||||||||||||||||||||||||||||||||||||
total_pages = data.get("pages", 1) | ||||||||||||||||||||||||||||||||||||
for item in data.get("items", []): | ||||||||||||||||||||||||||||||||||||
imdb_id = item.get("imDbId") | ||||||||||||||||||||||||||||||||||||
total_pages = getattr(data, "pages", 1) | ||||||||||||||||||||||||||||||||||||
for item in getattr(data, "items", []): | ||||||||||||||||||||||||||||||||||||
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 commentThe 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
Suggested change
🧰 Tools🪛 Ruff (0.8.2)60-60: Do not call Replace (B009) 63-63: Do not call Replace (B009) 64-64: Do not call Replace (B009) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||
if imdb_id: | ||||||||||||||||||||||||||||||||||||
unique_ids.add(imdb_id) | ||||||||||||||||||||||||||||||||||||
except HTTPError as e: | ||||||||||||||||||||||||||||||||||||
|
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: