From cdcdc5323bd072f59553ccbb7a3b0e36fa8622a0 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Fri, 22 Mar 2024 12:57:46 +0000 Subject: [PATCH] add containers eager to reading api query --- nowcasting_datamodel/read/read_user.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nowcasting_datamodel/read/read_user.py b/nowcasting_datamodel/read/read_user.py index f4b5c16d..e52cdc44 100644 --- a/nowcasting_datamodel/read/read_user.py +++ b/nowcasting_datamodel/read/read_user.py @@ -4,6 +4,7 @@ from datetime import datetime from typing import List, Optional +from sqlalchemy.orm import contains_eager from sqlalchemy.orm.session import Session from nowcasting_datamodel.models.api import APIRequestSQL, UserSQL @@ -57,6 +58,7 @@ def get_all_last_api_request(session: Session) -> List[APIRequestSQL]: session.query(APIRequestSQL) .distinct(APIRequestSQL.user_uuid) .join(UserSQL) + .options(contains_eager(APIRequestSQL.user)).populate_existing() .order_by(APIRequestSQL.user_uuid, APIRequestSQL.created_utc.desc()) .all() )