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

fix(user-report): Make all fields but event-id optional #886

Merged
merged 8 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Bug Fixes**:

- Make all fields but event-id optional to fix regressions in user feedback ingestion. ([#886](https://github.com/getsentry/relay/pull/886))
jan-auer marked this conversation as resolved.
Show resolved Hide resolved

## 20.12.1

- No documented changes.
Expand Down
26 changes: 25 additions & 1 deletion relay-general/src/protocol/user_report.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
use crate::protocol::EventId;

use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Deserializer, Serialize};

/// User feedback for an event as sent by the client to the userfeedback/userreport endpoint.
///
/// Historically the "schema" for user report has been "defined" as the set of possible
/// keyword-arguments `sentry.models.UserReport` accepts. Anything the model constructor
/// accepts goes.
///
/// For example, `{"email": null}` is only invalid because `UserReport(email=None).save()` is. SDKs
/// may neither send this (historically, in Relay we relaxed this already), but more importantly
/// the ingest consumer may never receive this... because it would end up crashing the ingest
/// consumer (while in older versions of Sentry it would simply crash the endpoint).
///
/// The database/model schema is a bunch of not-null strings that have (pgsql) defaults, so that's
/// how we end up with this struct definition.
#[derive(Debug, Deserialize, Serialize)]
pub struct UserReport {
/// The event ID for which this user feedback is created.
pub event_id: EventId,
/// The user's name.
#[serde(default, deserialize_with = "null_to_default")]
pub name: String,
/// The user's email address.
#[serde(default, deserialize_with = "null_to_default")]
pub email: String,
/// Comments supplied by the user.
#[serde(default, deserialize_with = "null_to_default")]
pub comments: String,
}

fn null_to_default<'de, D, V>(deserializer: D) -> Result<V, D::Error>
where
D: Deserializer<'de>,
V: Default + DeserializeOwned,
{
let opt = Option::deserialize(deserializer)?;
Ok(opt.unwrap_or_default())
}