-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Currently, a types.Map only supports full updates. This can be an issue with concurrent additions.
Consider:
# ============= models.py
class Model(engine.model):
id = Column(String, hash_key=True)
document = Column(**{
'bar': Integer,
'baz': Integer
})
engine.bind()
# ============= Thread 1
from models import engine, Model
model = Model(id='foo')
engine.load(model)
model.document['bar'] = 1
engine.save(model)
# ============= Thread 2
from models import engine, Model
model = Model(id='foo')
engine.load(model)
model.document['baz'] = 1
engine.save(model)
If we now load the model, it will have either bar or baz populated (and not the other), whichever thread wrote last.
There are plenty of ways to monitor which keys have been modified for a dict subclass, but when the value is directly a dict it's not possible to replace references to that dictionary with a custom one.
model.document['foo'] can be intercepted if document is already a dict subclass.
This cannot: model.document = {'foo': 'bar'}.