2014-01-29 15:17:37 |
Max Lobur |
description |
There are a bunch of places where we putting "{ }" as default to the JSONEncodedDict column:
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L473
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L413
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L297
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L295
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L293
This leads to writing the db value as ' "{ }" ' (https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/models.py#L59)
When the object is deserialized from the DB the property becomes string instead of dict, which may cause unexpected errors (due to interfaces mismatch).
I propose the following solution:
1. Remove all the places from DB API where JSONEncodedDict default is defined (all mentioned above)
2. Change JSONEncodedDict implementation to
def process_bind_param(self, value, dialect):
if value is None:
value = dict()
value = json.dumps(value)
return value |
There are a bunch of places where we putting "{ }" as default to the JSONEncodedDict column:
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L473
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L413
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L297
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L295
https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/api.py#L293
This leads to writing the db value as ' "{ }" ' (https://github.com/openstack/ironic/blob/master/ironic/db/sqlalchemy/models.py#L59)
When the object is deserialized from the DB the property becomes string instead of dict, which may cause unexpected errors (due to interfaces mismatch). Currently we
don't have any problems with this because the UOM tries to deserialize the dict value again (https://github.com/openstack/ironic/blob/master/ironic/objects/utils.py#L68-L69)
But this looks like a workaround so it's better to fix the original problem
This is how it looks like in DB (Note that non-empy extra serialized as expected {} whereas empty extra is "{}") http://paste.openstack.org/show/62103/
I propose the following solution:
1. Remove all the places from DB API where JSONEncodedDict default is defined (all mentioned above)
2. Change JSONEncodedDict implementation to
def process_bind_param(self, value, dialect):
if value is None:
value = dict()
value = json.dumps(value)
return value |
|