Skip to content

Commit

Permalink
Clarify use of constraint deferral
Browse files Browse the repository at this point in the history
  • Loading branch information
Jkrzy committed Jan 24, 2019
1 parent bdcd587 commit b096f40
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tock/hours/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,18 @@ def clean(self):

def save(self, commit=True):
"""
Save with deferred constraints
Allowing users to swap project IDs between TimeCardObjects
Incoming TimeCardObjectForms may violate the unique by (project_id, timecard_id)
constraint if users are swapping project_ids across TimeCardObjects which already
exist in the database.
From the user's perspective, the submitted timecard is valid and
so long as the final state of the TimeCardObject table and the Timecard itself is valid
we must accept the changes.
To do that, we save the formset with constraints deferred so that
they are checked at the end of the transaction.
Additional details: https://github.com/18F/tock/issues/887
"""
cur = connection.cursor()
with transaction.atomic():
Expand Down

0 comments on commit b096f40

Please sign in to comment.