From 5bd74c9eb770525e9af346753540a107f5228bfb Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Tue, 27 Sep 2022 18:42:22 +0200 Subject: [PATCH] Make sure we return always the last created API key --- lib/galaxy/managers/api_keys.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/managers/api_keys.py b/lib/galaxy/managers/api_keys.py index e08e58b7feb6..a155a9bce103 100644 --- a/lib/galaxy/managers/api_keys.py +++ b/lib/galaxy/managers/api_keys.py @@ -13,7 +13,12 @@ def __init__(self, app: BasicSharedApp): def get_api_key(self, user: User) -> Optional[APIKeys]: sa_session = self.app.model.context - api_key = sa_session.query(APIKeys).filter_by(user_id=user.id, deleted=False).first() + api_key = ( + sa_session.query(APIKeys) + .filter_by(user_id=user.id, deleted=False) + .order_by(APIKeys.create_time.desc()) + .first() + ) return api_key def create_api_key(self, user: User) -> APIKeys: