"""
from __future__ import absolute_import
+from sqlalchemy import inspect
from ..orm.attributes import flag_modified
from ..ext.hybrid import hybrid_property
def fset(self, instance, value):
attr_name = self.attr_name
- column_value = getattr(instance, attr_name)
+ column_value = getattr(instance, attr_name, None)
if column_value is None:
column_value = self.datatype()
setattr(instance, attr_name, column_value)
column_value[self.index] = value
setattr(instance, attr_name, column_value)
- flag_modified(instance, attr_name)
+ if attr_name in inspect(instance).mapper.attrs:
+ flag_modified(instance, attr_name)
def fdel(self, instance):
attr_name = self.attr_name
jq = s.query(Json).filter(Json.subfield == 'multi').first()
eq_(j.id, jq.id)
+
+ def test_nested_property_init(self):
+ Json = self.classes.Json
+
+ # subfield initializer
+ j = Json(subfield='a')
+ eq_(j.json, {'other': {'field': 'a'}})
+
+ def test_nested_property_set(self):
+ Json = self.classes.Json
+
+ j = Json()
+ j.subfield = 'a'
+ eq_(j.json, {'other': {'field': 'a'}})