summaryrefslogtreecommitdiffstats
path: root/nova/exception.py
diff options
context:
space:
mode:
authorMike Lundy <mike@pistoncloud.com>2012-03-02 00:15:04 +0000
committerMike Lundy <mike@pistoncloud.com>2012-03-02 02:24:33 +0000
commit27013e87f53cccbfd2e203f065e416437ba08987 (patch)
treed6609f0fd9b6f5333206676debdef1321acadac6 /nova/exception.py
parent20346926533a6ef6f4cd1ddf4e4123ecefbabc72 (diff)
downloadnova-27013e87f53cccbfd2e203f065e416437ba08987.tar.gz
nova-27013e87f53cccbfd2e203f065e416437ba08987.tar.xz
nova-27013e87f53cccbfd2e203f065e416437ba08987.zip
Fail gracefully when the db doesn't speak unicode
When sqlalchemy/mysql doesn't contain the charset=utf8 or use_unicode=1 parameters (and the default mysql connection charset is not utf8), sqlalchemy will connect to mysql in ascii mode; In ascii mode, it will attempt to reencode all input data to latin-1 regardless of the database/table collation setting. This catches that error and turns it into an invalid parameter. (The error message associated with this is something like UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2026' in position 30: ordinal not in range(256)) This fixes bug 944034 and is related to bug 898808 Change-Id: I082b7568ef9e9d2104e13aa58d207535ef201bd3
Diffstat (limited to 'nova/exception.py')
-rw-r--r--nova/exception.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/nova/exception.py b/nova/exception.py
index 3caab9465..43d16642f 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -88,6 +88,8 @@ def wrap_db_error(f):
def _wrap(*args, **kwargs):
try:
return f(*args, **kwargs)
+ except UnicodeEncodeError:
+ raise InvalidUnicodeParameter()
except Exception, e:
LOG.exception(_('DB exception wrapped.'))
raise DBError(e)
@@ -275,6 +277,11 @@ class InvalidRPCConnectionReuse(Invalid):
message = _("Invalid reuse of an RPC connection.")
+class InvalidUnicodeParameter(Invalid):
+ message = _("Invalid Parameter: "
+ "Unicode is not supported by the current database.")
+
+
# Cannot be templated as the error syntax varies.
# msg needs to be constructed when raised.
class InvalidParameterValue(Invalid):