From f28d9f4f7b222119b5c5481eb7d318695ce43c95 Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Wed, 21 Aug 2013 14:23:04 -0500 Subject: [PATCH] Fix error where consumer is not deleted from sql Looks like when the token sql backend was going through tokens to delete, it didn't like if the token ref didn't have a token field. I placed a guard in there now. fixes bug: #1215493 Change-Id: Ia12f5e4d9af71c322c9230464ae39ec88303b600 --- keystone/contrib/oauth1/backends/sql.py | 2 +- keystone/token/backends/sql.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/keystone/contrib/oauth1/backends/sql.py b/keystone/contrib/oauth1/backends/sql.py index 9dc0665c4a..be5c97ac20 100644 --- a/keystone/contrib/oauth1/backends/sql.py +++ b/keystone/contrib/oauth1/backends/sql.py @@ -108,7 +108,7 @@ def create_consumer(self, consumer): return consumer_ref.to_dict() def _delete_consumer(self, session, consumer_id): - consumer_ref = self._get_consumer(session, consumer_id) + consumer_ref = self._get_consumer(consumer_id) q = session.query(Consumer) q = q.filter_by(id=consumer_id) q.delete(False) diff --git a/keystone/token/backends/sql.py b/keystone/token/backends/sql.py index 5d24fb4ff0..7b3728e0a4 100644 --- a/keystone/token/backends/sql.py +++ b/keystone/token/backends/sql.py @@ -118,12 +118,15 @@ def _tenant_matches(self, tenant_id, token_ref_dict): (token_ref_dict.get('tenant') and token_ref_dict['tenant'].get('id') == tenant_id)) - def _consumer_matches(self, consumer_id, token_ref_dict): + def _consumer_matches(self, consumer_id, ref): if consumer_id is None: return True else: - oauth = token_ref_dict['token_data']['token'].get('OS-OAUTH1', {}) - return oauth and oauth['consumer_id'] == consumer_id + try: + oauth = ref['token_data']['token'].get('OS-OAUTH1', {}) + return oauth and oauth['consumer_id'] == consumer_id + except KeyError: + return False def _list_tokens_for_trust(self, trust_id): session = self.get_session()