diff --git a/warehouse/macaroons/services.py b/warehouse/macaroons/services.py index 7c18dbdb4cf4..040f7956edea 100644 --- a/warehouse/macaroons/services.py +++ b/warehouse/macaroons/services.py @@ -16,7 +16,6 @@ import pymacaroons from pymacaroons.exceptions import MacaroonDeserializationException -from sqlalchemy.exc import NoResultFound from sqlalchemy.orm import joinedload from zope.interface import implementer @@ -199,16 +198,12 @@ def get_macaroon_by_description(self, user_id, description): Returns None if the user doesn't have a macaroon with this description. """ - try: - dm = ( - self.db.query(Macaroon) - .options(joinedload("user")) - .filter(Macaroon.description == description) - .filter(Macaroon.user_id == user_id) - .one() - ) - except NoResultFound: - return None + dm = ( + self.db.query(Macaroon) + .filter(Macaroon.description == description) + .filter(Macaroon.user_id == user_id) + .one_or_none() + ) return dm