Skip to content

Commit

Permalink
Usage of transaction.atomic decorator.
Browse files Browse the repository at this point in the history
#26 , #103
This wraps the entire method into an atomic block rather than just a
portion of it.
  • Loading branch information
avelis committed Mar 4, 2016
1 parent b5f1229 commit 947e397
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions silk/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,16 @@ def process_request(self, request):
request_model = RequestModelFactory(request).construct_request_model()
DataCollector().configure(request_model)

@transaction.atomic()
def _process_response(self, response):
Logger.debug('Process response')
with silk_meta_profiler():
collector = DataCollector()
collector.stop_python_profiler()
silk_request = collector.request
if silk_request:
try:
with transaction.atomic():
silk_response = ResponseModelFactory(response).construct_response_model()
silk_response.save()
except IntegrityError as e:
Logger.error('Silk IntegrityError: {}'.format(e))

silk_request.end_time = timezone.now()
collector.finalise()
silk_response = ResponseModelFactory(response).construct_response_model()
silk_response.save()
else:
Logger.error(
'No request model was available when processing response. Did something go wrong in process_request/process_view?')
Expand Down

2 comments on commit 947e397

@Wrhector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit removes the
collector.finalise()
call, thus breaking the saving of anything collected (SQL, profiling)

@avelis
Copy link
Collaborator Author

@avelis avelis commented on 947e397 Mar 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wrhector. You are correct. A mistake on my part.

Please sign in to comment.