Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending raw body to sentry #760

Merged
merged 28 commits into from
Aug 18, 2023

Conversation

why-not-try-calmer
Copy link
Contributor

@why-not-try-calmer why-not-try-calmer commented Aug 3, 2023

A few clarifications and observations:

  • Actually this is fine => DownloadPushDeleteFileView.post() does not trigger the parse() method of its declared parser_class (MultiPartParser), because I did subclass this parser class in a previous version of this PR, and my override of parse() never triggered in my tests
  • This is done => room for improvement: ensure that the intended parse() function is called, so that we can debug more from that context; this might open the door to reading the request.body only for requests that fail, and not all of them as is the case here.

@duke-nyuki
Copy link
Collaborator

@why-not-try-calmer why-not-try-calmer marked this pull request as ready for review August 4, 2023 10:19
@why-not-try-calmer why-not-try-calmer added the chore Maintanance, clean-up and other not fancy improvements. label Aug 4, 2023
@why-not-try-calmer
Copy link
Contributor Author

why-not-try-calmer commented Aug 8, 2023

Raw body:
request_id_file_name_rawbody.txt

More samples on Sentry.

Alternatively, as I said in the Daily (perhaps also of interest for you @m-kuhn since you said you really, really would like to see a full request), a request object could cloned-then-serialized with:

import shutil
import copy

cloned_request: wsgi.WSGIRequest = copy.deepcopy(request)
output_stream = io.BytesIO()
shutil.copyfileobj(cloned_request, output_stream)

Copy link
Collaborator

@suricactus suricactus left a comment

Choose a reason for hiding this comment

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

Looks good, two small comments and one idea we communicate in the chat.

@suricactus
Copy link
Collaborator

suricactus commented Aug 16, 2023

Not sure why the changes replaced in 989c7b6 were existing?

@suricactus
Copy link
Collaborator

suricactus commented Aug 16, 2023

@why-not-try-calmer this seems does not work with real life example outside the test case. At least in my local experiments, I have tried to upload a file and enter the if sending to Sentry as in files_views.py.

What I have observed is that the middleware and the views are having different request objects, one intsance of WSGIRequest and the other one is DRFRequest. Therefore getattr(request, 'body_stream', None) always returns None outside the test scenario. I guess I am missing something or I might have broken something with my changes.

Can you please post your steps of testing with real world file upload? Thanks!

@suricactus
Copy link
Collaborator

@why-not-try-calmer all works fine, seems it was a misconfiguration from my side. Allowed myself a final change before merging.

Thanks for sorting this out!

@why-not-try-calmer
Copy link
Contributor Author

why-not-try-calmer commented Aug 17, 2023

@why-not-try-calmer all works fine, seems it was a misconfiguration from my side. Allowed myself a final change before merging.

Thanks for sorting this out!

Looks ready to merge! (I would approve but I am the PR author so I cannot)

@suricactus suricactus merged commit d79370c into master Aug 18, 2023
@suricactus suricactus deleted the QF-2704_adding-body-to-attach-keys-middlware branch August 18, 2023 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintanance, clean-up and other not fancy improvements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants