Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions silk/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,29 @@ def process_request(self, request):
request_model = RequestModelFactory(request).construct_request_model()
DataCollector().configure(request_model, should_profile=should_profile)

@transaction.atomic(using=router.db_for_write(models.SQLQuery))
def _process_response(self, request, response):
Logger.debug('Process response')
with silk_meta_profiler():
collector = DataCollector()
collector.stop_python_profiler()
silk_request = collector.request
with transaction.atomic(using=router.db_for_write(models.SQLQuery)):
Copy link
Member

Choose a reason for hiding this comment

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

It would be helpful to add a comment here describing why this is a with block instead of a decorator. This was actually the subject of a discussion in #801 but it did not go over the possibility of the database mutating at runtime.

Logger.debug('Process response')
with silk_meta_profiler():
collector = DataCollector()
collector.stop_python_profiler()
silk_request = collector.request
if silk_request:
ResponseModelFactory(response).construct_response_model()
silk_request.end_time = timezone.now()
collector.finalise()
else:
Logger.error(
'No request model was available when processing response. '
'Did something go wrong in process_request/process_view?'
'\n' + str(request) + '\n\n' + str(response)
)
# Need to save the data outside the silk_meta_profiler
# Otherwise the meta time collected in the context manager
# is not taken in account
if silk_request:
ResponseModelFactory(response).construct_response_model()
silk_request.end_time = timezone.now()
collector.finalise()
else:
Logger.error(
'No request model was available when processing response. '
'Did something go wrong in process_request/process_view?'
'\n' + str(request) + '\n\n' + str(response)
)
# Need to save the data outside the silk_meta_profiler
# Otherwise the meta time collected in the context manager
# is not taken in account
if silk_request:
silk_request.save()
Logger.debug('Process response done.')
silk_request.save()
Logger.debug('Process response done.')

def process_response(self, request, response):
max_attempts = 2
Expand Down