Skip to content

Commit

Permalink
max depth fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkersigirci committed Jan 18, 2025
1 parent e487c67 commit 029446f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api/utils/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def fuzzy_search_movies(

@timing_decorator
def get_random_movie_with_details(
min_backdrops: int = 5, category: str = "popular"
min_backdrops: int = 5,
category: str = "popular",
depth: int = 0,
max_depth: int = 5,
) -> dict:
"""Get a random movie with at least specified number of backdrops.
Expand All @@ -172,7 +175,11 @@ def get_random_movie_with_details(
logger.debug(
f"Movie {movie.title} has {len(backdrops)} backdrops, trying another..."
)
return get_random_movie_with_details(min_backdrops, category, depth + 1) if depth < max_depth else {'error': 'Max recursion depth reached'}
return (
get_random_movie_with_details(min_backdrops, category, depth + 1)
if depth < max_depth
else {"error": "Max recursion depth reached"}
)

return {
"id": movie.id,
Expand Down

0 comments on commit 029446f

Please sign in to comment.