Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
Don't force raise_on_conflict=True for changed composite fields
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jun 23, 2015
1 parent 7c3b612 commit e13d1a4
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions flywheel/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,20 +548,9 @@ def sync(self, items, raise_on_conflict=None, consistent=False, constraints=None
fields = item.__dirty__
item.pre_save_(self)

# If the model has changed any field that is part of a composite
# field, FORCE the sync to raise on conflict. This prevents the
# composite key from potentially getting into an inconsistent state
_raise_on_conflict = raise_on_conflict
for name in itertools.chain(item.__incrs__, fields):
for related_name in item.meta_.related_fields.get(name, []):
field = item.meta_.fields[related_name]
if field.composite:
_raise_on_conflict = True
break

keywords = {}
constrained_fields = set()
if _raise_on_conflict and constraints is not None:
if raise_on_conflict and constraints is not None:
for constraint in constraints:
constrained_fields.update(constraint.eq_fields.keys())
constrained_fields.update(constraint.fields.keys())
Expand All @@ -573,7 +562,7 @@ def sync(self, items, raise_on_conflict=None, consistent=False, constraints=None
field = item.meta_.fields.get(name)
value = getattr(item, name)
kwargs = {}
if _raise_on_conflict and name not in constrained_fields:
if raise_on_conflict and name not in constrained_fields:
kwargs = {'eq': item.ddb_dump_cached_(name)}
update = ItemUpdate.put(name, item.ddb_dump_field_(name),
**kwargs)
Expand Down

0 comments on commit e13d1a4

Please sign in to comment.