summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDolph Mathews <dolph.mathews@gmail.com>2012-01-26 15:29:34 -0600
committerDolph Mathews <dolph.mathews@gmail.com>2012-01-26 15:29:34 -0600
commitd2e6f63fe107c17e344337b8db030733ed9bbb2e (patch)
tree9850b9ee58dd217420b5aee5f5319dd6399e6b67
parent2abbc77df6c5d9b0cbb94019285bb9527bf224c3 (diff)
Added shortcut for id=NULL queries (bug 916386)
Change-Id: I9d7ae05f860d4a8f56bb9b7ab77221e201478393
-rwxr-xr-xkeystone/backends/sqlalchemy/api/credentials.py6
-rwxr-xr-xkeystone/backends/sqlalchemy/api/endpoint_template.py6
-rwxr-xr-xkeystone/backends/sqlalchemy/api/role.py6
-rw-r--r--keystone/backends/sqlalchemy/api/service.py6
-rwxr-xr-xkeystone/backends/sqlalchemy/api/tenant.py12
-rwxr-xr-xkeystone/backends/sqlalchemy/api/token.py6
-rwxr-xr-xkeystone/backends/sqlalchemy/api/user.py31
7 files changed, 51 insertions, 22 deletions
diff --git a/keystone/backends/sqlalchemy/api/credentials.py b/keystone/backends/sqlalchemy/api/credentials.py
index a3dd5bea..22105694 100755
--- a/keystone/backends/sqlalchemy/api/credentials.py
+++ b/keystone/backends/sqlalchemy/api/credentials.py
@@ -99,8 +99,10 @@ class CredentialsAPI(api.BaseCredentialsAPI):
@staticmethod
def _get(id, session=None):
- if not session:
- session = get_session()
+ if id is None:
+ return None
+
+ session = session or get_session()
return session.query(models.Credentials).filter_by(id=id).first()
diff --git a/keystone/backends/sqlalchemy/api/endpoint_template.py b/keystone/backends/sqlalchemy/api/endpoint_template.py
index 25fe0ed4..84fce454 100755
--- a/keystone/backends/sqlalchemy/api/endpoint_template.py
+++ b/keystone/backends/sqlalchemy/api/endpoint_template.py
@@ -61,8 +61,10 @@ class EndpointTemplateAPI(api.BaseEndpointTemplateAPI):
session.delete(endpoint_template)
def get(self, id, session=None):
- if not session:
- session = get_session()
+ if id is None:
+ return None
+
+ session = session or get_session()
return session.query(models.EndpointTemplates).\
filter_by(id=id).first()
diff --git a/keystone/backends/sqlalchemy/api/role.py b/keystone/backends/sqlalchemy/api/role.py
index 7ffe13e8..62198e76 100755
--- a/keystone/backends/sqlalchemy/api/role.py
+++ b/keystone/backends/sqlalchemy/api/role.py
@@ -89,8 +89,10 @@ class RoleAPI(api.BaseRoleAPI):
ref.save(session=session)
def get(self, id, session=None):
- if not session:
- session = get_session()
+ if id is None:
+ return None
+
+ session = session or get_session()
return RoleAPI.to_model(
session.query(models.Role).filter_by(id=id).first())
diff --git a/keystone/backends/sqlalchemy/api/service.py b/keystone/backends/sqlalchemy/api/service.py
index 0ffb4f28..3e546106 100644
--- a/keystone/backends/sqlalchemy/api/service.py
+++ b/keystone/backends/sqlalchemy/api/service.py
@@ -102,8 +102,10 @@ class ServiceAPI(api.BaseServiceAPI):
service_ref.save(session=session)
def get(self, id, session=None):
- if not session:
- session = get_session()
+ if id is None:
+ return None
+
+ session = session or get_session()
return ServiceAPI.to_model(session.query(models.Service).
filter_by(id=id).first())
diff --git a/keystone/backends/sqlalchemy/api/tenant.py b/keystone/backends/sqlalchemy/api/tenant.py
index 32432e5a..db516b15 100755
--- a/keystone/backends/sqlalchemy/api/tenant.py
+++ b/keystone/backends/sqlalchemy/api/tenant.py
@@ -81,6 +81,9 @@ class TenantAPI(api.BaseTenantAPI):
For PK lookups from within the sqlalchemy backend,
use ``_get_by_id()`` instead.
"""
+ if id is None:
+ return None
+
session = session or get_session()
result = session.query(models.Tenant).filter_by(uid=id).first()
@@ -97,18 +100,27 @@ class TenantAPI(api.BaseTenantAPI):
This is **only** for use within the sqlalchemy backend.
"""
+ if id is None:
+ return None
+
session = session or get_session()
return session.query(models.Tenant).filter_by(id=id).first()
@staticmethod
def id_to_uid(id, session=None):
+ if id is None:
+ return None
+
session = session or get_session()
tenant = session.query(models.Tenant).filter_by(id=id).first()
return tenant.uid if tenant else None
@staticmethod
def uid_to_id(uid, session=None):
+ if uid is None:
+ return None
+
session = session or get_session()
tenant = session.query(models.Tenant).filter_by(uid=uid).first()
return tenant.id if tenant else None
diff --git a/keystone/backends/sqlalchemy/api/token.py b/keystone/backends/sqlalchemy/api/token.py
index e2624a9c..869822bb 100755
--- a/keystone/backends/sqlalchemy/api/token.py
+++ b/keystone/backends/sqlalchemy/api/token.py
@@ -78,8 +78,10 @@ class TokenAPI(api.BaseTokenAPI):
@staticmethod
def _get(id, session=None):
- if not session:
- session = get_session()
+ if id is None:
+ return None
+
+ session = session or get_session()
result = session.query(models.Token).filter_by(id=id).first()
diff --git a/keystone/backends/sqlalchemy/api/user.py b/keystone/backends/sqlalchemy/api/user.py
index 156d79db..f5a64b18 100755
--- a/keystone/backends/sqlalchemy/api/user.py
+++ b/keystone/backends/sqlalchemy/api/user.py
@@ -80,11 +80,12 @@ class UserAPI(api.BaseUserAPI):
return UserAPI.to_model(user_ref)
def get(self, id, session=None):
- if not session:
- session = get_session()
+ if id is None:
+ return None
- id = str(id) if id is not None else None
- result = session.query(models.User).filter_by(uid=id).first()
+ session = session or get_session()
+
+ result = session.query(models.User).filter_by(uid=str(id)).first()
return UserAPI.to_model(result)
@@ -95,24 +96,30 @@ class UserAPI(api.BaseUserAPI):
- Queries by PK ID
- Doesn't wrap result with domain layer models
"""
- if not session:
- session = get_session()
+ if id is None:
+ return None
+
+ session = session or get_session()
- id = str(id) if id is not None else None
- return session.query(models.User).filter_by(id=id).first()
+ # TODO(dolph): user ID's are NOT strings... why is this is being cast?
+ return session.query(models.User).filter_by(id=str(id)).first()
@staticmethod
def id_to_uid(id, session=None):
+ if id is None:
+ return None
+
session = session or get_session()
- id = str(id) if id is not None else None
- user = session.query(models.User).filter_by(id=id).first()
+ user = session.query(models.User).filter_by(id=str(id)).first()
return user.uid if user else None
@staticmethod
def uid_to_id(uid, session=None):
+ if uid is None:
+ return None
+
session = session or get_session()
- uid = str(uid) if uid is not None else None
- user = session.query(models.User).filter_by(uid=uid).first()
+ user = session.query(models.User).filter_by(uid=str(uid)).first()
return user.id if user else None
def get_by_name(self, name, session=None):