Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

avoid ConcurrencyError in CaseVersionResource #26

Merged
merged 1 commit into from Mar 21, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions moztrap/model/library/api.py
Expand Up @@ -225,6 +225,24 @@ def read_create_fields(self):
return ["case", "productversion"] return ["case", "productversion"]




def obj_update(self, bundle, request=None, **kwargs):
"""Set the modified_by field for the object to the request's user,
avoid ConcurrencyError by updating cc_version."""
# this try/except logging is more helpful than 500 / 404 errors on the
# client side
bundle = self.check_read_create(bundle)
try:
bundle = super(MTResource, self).obj_update(
bundle=bundle, request=request, **kwargs)
# avoid ConcurrencyError
bundle.obj.cc_version = self.model.objects.get(
id=bundle.obj.id).cc_version
bundle.obj.save(user=request.user)
return bundle
except Exception: # pragma: no cover
logger.exception("error updating %s", bundle) # pragma: no cover
raise # pragma: no cover

def hydrate_productversion(self, bundle): def hydrate_productversion(self, bundle):
"""case.product must match productversion.product on CREATE""" """case.product must match productversion.product on CREATE"""


Expand Down