# HG changeset patch # User Daniel Dourvaris # Date 2016-06-22 15:18:59 # Node ID 81a58befd9b0d95c2c9180713788235ea2bd1405 # Parent 39d20fee2ce59038550716b766f79a04cb64b72a model: make sure only 1 repo in session when get_by_repo_name diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -1374,10 +1374,15 @@ class Repository(Base, BaseModel): @classmethod def get_by_repo_name(cls, repo_name): session = Session() + exist_in_session = [] for (item_cls, pkey), instance in session.identity_map.items(): if cls == item_cls and instance.repo_name == repo_name: - return instance - + exist_in_session.append(instance) + if exist_in_session: + if len(exist_in_session) > 1: + raise Exception('2 same name repos in session') + return exist_in_session[0] + q = session.query(cls).filter(cls.repo_name == repo_name) return q.scalar()