From 500a2e337fb21cda6ea612cdbd9eb601cf2e3462 Mon Sep 17 00:00:00 2001 From: Stein A Sivertsen Date: Thu, 30 Nov 2023 13:31:29 +0000 Subject: [PATCH] create a copy to return, not to modify datastore with quote --- ex-11/got-episodes-api-python/src/routes/episodes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ex-11/got-episodes-api-python/src/routes/episodes.py b/ex-11/got-episodes-api-python/src/routes/episodes.py index f2d18d3..33a1917 100644 --- a/ex-11/got-episodes-api-python/src/routes/episodes.py +++ b/ex-11/got-episodes-api-python/src/routes/episodes.py @@ -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):