Skip to content

Commit

Permalink
create a copy to return, not to modify datastore with quote
Browse files Browse the repository at this point in the history
  • Loading branch information
steinsiv authored Nov 30, 2023
1 parent f3abe6e commit 500a2e3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ex-11/got-episodes-api-python/src/routes/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def get_all_episodes(token: str = Depends(get_token_header)):
episodes = episodes_controller.get_all_episodes()
quote = episodes_controller.get_random_quote(obo_token)
logger.info(f"{type(episodes) = } {type(quote) = }")
episodes.append(quote)
logger.info(f"{episodes = }")
return episodes
# Create a copy of the episodes list and append the quote to it
result = episodes.copy()
result.append(quote)
logger.info(f"{result = }")
return result

@router.get("/episodes/{episode_id}", response_model=Episode)
def get_episode(episode_id: int):
Expand Down

0 comments on commit 500a2e3

Please sign in to comment.