Skip to content

Commit 9c06af3

Browse files
authored
Fix: Handle invalid data in build_movies (#128)
2 parents e490548 + 96780f1 commit 9c06af3

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

trakt/users.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
"""Interfaces to all of the User objects offered by the Trakt.tv API"""
33

4+
import logging
45
from dataclasses import dataclass, fields
56
from typing import Any, NamedTuple, Optional, Union
67

@@ -16,6 +17,7 @@
1617
__all__ = ['User', 'UserList', 'PublicList', 'Request', 'follow', 'get_all_requests',
1718
'get_user_settings', 'unfollow']
1819

20+
logger = logging.getLogger(__name__)
1921

2022
class Request(NamedTuple):
2123
id: int
@@ -522,11 +524,19 @@ def _build_movies(data):
522524
:param data: List of raw movie dicts from the Trakt API
523525
:return: List of :class:`Movie` instances
524526
"""
527+
525528
movies = []
526529
for movie in data:
527530
movie_data = movie.pop('movie')
531+
# Title is required for Movie model
532+
if movie_data.get('title') is None:
533+
original = dict(**movie, **{'movie': movie_data})
534+
logger.warning("Ignoring invalid Movie with no title: %s", original)
535+
continue
536+
528537
movie_data.update(movie)
529538
movies.append(Movie(**movie_data))
539+
530540
return movies
531541

532542
@get

0 commit comments

Comments
 (0)