[Sqlalchemy-tickets] Issue #3646: MutableDict creates only on first level of JSON (zzzeek/sqlalchem
Brought to you by:
zzzeek
From: Valentin K. <iss...@bi...> - 2016-02-10 14:10:00
|
New issue 3646: MutableDict creates only on first level of JSON https://bitbucket.org/zzzeek/sqlalchemy/issues/3646/mutabledict-creates-only-on-first-level-of Valentin Kaplov: If we associate MutableDict with JSON data, then MutableDict accociates with first level elements only. As result if we have on second and/or next levels mutable objects (like list, dict) and we modify them, then MutableDict will not marked as dirty/changed and modification will not take effect to database. Thus we'll lose consistency. Example. We have next JSON data from database: ``` #!python { "key1": {"key1.2": "value1.2"}, "key2": ["value2.1", "value2.2"], "key3": "value3", } ``` If we pass the data to MutableDict, then it will create next object tree: **Actual result:** ``` #!python m_dict = MutableDict({ "key1": dict({"key1.2": "value1.2"}), # value builtin dict "key2": list(["value2.1", "value2.2"]), # value builtin list "key3": "value3" }) m_dict['key1']['key1.2'] = 'new_value' # m_dict doesn't marked as changed m_dict['key1'][0] = 'new_value' # m_dict doesn't marked as changed ``` **Expected result:** ``` #!python MutableDict({ "key1": MutableDict({"key1.2": "value1.2"}) # value MutableDict asocciated with JSON "key2": MutableList(["value2.1", "value2.2"]), # value MutableDict asocciated with JSON "key3": "value3" }) m_dict['key1']['key1.2'] = 'new_value' # m_dict marked as changed m_dict['key1'][0] = 'new_value' # m_dict marked as changed ``` **Additional information:** To fix the problem needs to have implemented MutableList https://bitbucket.org/zzzeek/sqlalchemy/issues/3297 Need to change all builtin mutables in JSON on corresponding associated Mutables from sqlalchemy. BTW Mirantis has already implemented wrappers that fix the bug. It can be usefull https://github.com/openstack/fuel-web/blob/master/nailgun/nailgun/db/sqlalchemy/models/mutable.py Responsible: zzzeek |