summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorAlex Meade <alex.meade@rackspace.com>2012-08-01 13:40:56 -0400
committerAlex Meade <alex.meade@rackspace.com>2012-08-01 14:30:30 -0400
commitef579789065bd5eca90404e29463c63d538c5a01 (patch)
tree252303ca7de2651ea155411092231b18787cc5cd /nova
parent3a5ea16bec06fceddfe06af343ee505cfc419a1b (diff)
Fix issue with filtering where a value is unicode.
This fixes an issue where if an attribute, such as name, for an instance contains unicode and doing a list of instances filtering by that attribute causes a 500 error. fixes bug 1031846 Change-Id: I2e9e9a36194dad1326b0d7257308576f8553ef06
Diffstat (limited to 'nova')
-rw-r--r--nova/db/sqlalchemy/api.py2
-rw-r--r--nova/tests/test_db_api.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 9e987055c..1f5b07643 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1521,7 +1521,7 @@ def instance_get_all_by_filters(context, filters, sort_key, sort_dir):
v = getattr(instance, filter_name)
except AttributeError:
return True
- if v and filter_re.match(str(v)):
+ if v and filter_re.match(unicode(v)):
return True
return False
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 344ac9a74..045f63e73 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -1,4 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
+# encoding=UTF8
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
@@ -45,6 +46,14 @@ class DbApiTestCase(test.TestCase):
result = db.instance_get_all_by_filters(self.context, {})
self.assertTrue(2, len(result))
+ def test_instance_get_all_by_filters_unicode_value(self):
+ args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1',
+ 'display_name': u'test♥'}
+ db.instance_create(self.context, args)
+ result = db.instance_get_all_by_filters(self.context.elevated(),
+ {'display_name': u'test'})
+ self.assertEqual(1, len(result))
+
def test_instance_get_all_by_filters_deleted(self):
args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
inst1 = db.instance_create(self.context, args1)