Fix TypeError of _get_project_id when project_id is None
If we get flavors with a domain token or an unscope token, the project id of this case is None, will raise "TypeError: 'in <string>' requires string as left operand, not NoneType" in _get_project_id. So, first we need check whether project_id is None or not. We can just return '' if project_id is None. Change-Id: I8477d08a956a5b0262bd473254d9202738b6b65b Closes-Bug: #1733746
This commit is contained in:
parent
8628c75738
commit
036a692565
|
@ -380,7 +380,7 @@ class ViewBuilder(object):
|
|||
otherwise
|
||||
"""
|
||||
project_id = request.environ["nova.context"].project_id
|
||||
if project_id in request.url:
|
||||
if project_id and project_id in request.url:
|
||||
return project_id
|
||||
return ''
|
||||
|
||||
|
|
|
@ -594,6 +594,11 @@ class ViewBuilderLinkTest(test.NoDBTestCase):
|
|||
proj_id = self.vb._get_project_id(self.request)
|
||||
self.assertEqual(self.project_id, proj_id)
|
||||
|
||||
def test_get_project_id_with_none_project_id(self):
|
||||
self.request.environ["nova.context"].project_id = None
|
||||
proj_id = self.vb._get_project_id(self.request)
|
||||
self.assertEqual('', proj_id)
|
||||
|
||||
def test_get_next_link(self):
|
||||
identifier = "identifier"
|
||||
collection = "collection"
|
||||
|
|
Loading…
Reference in New Issue