fix(server): pass on multipart attachments without content type#3225
Conversation
c751594 to
d5469bf
Compare
|
A few integration tests fail due to assertions that expect |
d5469bf to
4fbd340
Compare
relay-server/src/envelope.rs
Outdated
| /// Sets the payload and content-type of this envelope. | ||
| pub fn set_payload<B>(&mut self, content_type: ContentType, payload: B) | ||
| where | ||
| pub(crate) fn set_payload_optional_content_type<B>( |
There was a problem hiding this comment.
The original set_payload does two things: set the content_type and truncate the payload. In the PR, the content type is only set from set_payload but never directly. Splitting both actions makes the Item's API usage easier to understand (vs wondering what a None is for). For example:
// envelope.rs
fn set_payload(...) {
self.headers.content_type = content_type;
self.set_truncated_payload(...);
}
fn set_truncated_payload<B>(&mut self, payload: B) where B: Into<Bytes> {
// ...
}
// multipart.rs
if let Some(content_type) = field.content_type() {
item.set_payload(content_type, field_data);
} else {
item.set_truncated_payload(field_data);
}(not opinionated on the function name.)
Extending the docstrings to point to the other function, depending on the content_type needs, would be great.
relay-server/src/envelope.rs
Outdated
| self.payload = payload; | ||
| } | ||
|
|
||
| /// The primary payload setter requires a content-type, since most call-sites set it explicitly. |
There was a problem hiding this comment.
The original docstring is more descriptive:
| /// The primary payload setter requires a content-type, since most call-sites set it explicitly. | |
| /// Sets the payload and content-type of this envelope. |
Thanks, @iker-barriocanal. To be clear, would you like to add attachment tests for Is it okay to assert the attachment's |
Yep, test coverage for both branches of
Yes, that's what we're looking for in the end -- no Thanks for working on this, and let me know if you have further questions! |
4fbd340 to
756c5c4
Compare
|
Hi @iker-barriocanal, I tried to cover the mentioned issues. I used a "real-life" multipart payload for the unit test and minimized the contents to data required for the assertions. It should cover all PR-touched paths in |
iker-barriocanal
left a comment
There was a problem hiding this comment.
Thanks for your effort and tests! One last question before merging 😄
tests/integration/test_minidump.py
Outdated
| "id": attachment_id, | ||
| "name": "minidump.dmp", | ||
| "content_type": "application/octet-stream", | ||
| "content_type": None, |
There was a problem hiding this comment.
Q: Does sentry always expect the content_type field to exist?
Looking at this code maybe it does, but I'm not familiar with that part of the codebase. If it's ok to not include the field on null values, let's skip serializing it by adding a #[serde(skip_serializing_if = "Option::is_none")] to ChunkedAttachment.content_type on relay-server/src/services/store.rs.
There was a problem hiding this comment.
+1, sentry might expect the content type, we should make sure it can handle missing / null values.
There was a problem hiding this comment.
I am also not familiar with the code base. Still, when looking at the handling of attachments processed from envelope items (directly vs. via multipart), a non-existent content type appears to be valid input.
There was a problem hiding this comment.
Let me check internally and I'll get back to you
There was a problem hiding this comment.
It seems it's safe for content_type to be null or not exist (see sentry test), and sentry will also default to application/octet-stream if it can't guess the type.
@supervacuus let's skip the serialization when the field is empty as I posted on my comment above, and I'll merge the PR afterward.
iker-barriocanal
left a comment
There was a problem hiding this comment.
Thanks for putting in the effort and working on this!
I'll merge and deploy on Monday to avoid surprises on a Friday and weekend.
|
There were some difficulties in the infrastructure today and this PR is not live. I'll make another attempt tomorrow and post an update here when the change is live. |
|
@supervacuus the PR is deployed! |
Thanks for the update. I tested this with a patched |
This PR visualizes the change required to go forward with the approach suggested here: #3224
I introduced that
set_payload()interface asymmetry only to avoid changing all the call sites for this PR.