Skip to content

Map supports partial updates #28

@numberoverzero

Description

@numberoverzero

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'}.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions