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: make Strings in meta backwards compatible #4438

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

elsirion
Copy link
Contributor

For a long time we allowed plain strings in meta fields, i.e. without some ugly additional JSON quotation, but removed that bug/feature. Turns out that's a backwards incompatible change.

Related to #3648, #3699, #4432 and #4434.

Comment on lines +216 to +221
let string_ret = Box::new(str_value.clone());
let ret: Box<V> = unsafe {
// We can transmute a String to V because we know that V==String
std::mem::transmute(string_ret)
};
Ok(Some(*ret))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't able to do this with a plain V, the compiler complained about unknown size, this seemed like the easiest fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(@dpc used a similar unsafe trick elsewhere iirc, it's not new)

Copy link
Member

Choose a reason for hiding this comment

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

(@dpc used a similar unsafe trick elsewhere iirc, it's not new)

Yep, there's some insightful discussion related to this pattern in the PR that introduced it #4145

This looks good to me, but I'll defer approval to folks with more context.

@elsirion elsirion requested review from dpc and douglaz February 29, 2024 18:13
@elsirion elsirion marked this pull request as ready for review February 29, 2024 19:18
@elsirion elsirion requested a review from a team as a code owner February 29, 2024 19:18
Copy link
Contributor

@douglaz douglaz left a comment

Choose a reason for hiding this comment

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

Ugly but works

let string_ret = Box::new(str_value.clone());
let ret: Box<V> = unsafe {
// We can transmute a String to V because we know that V==String
std::mem::transmute(string_ret)
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting bounds here explicitly would make paranoid people feel a bit better about it.

@elsirion elsirion added this pull request to the merge queue Feb 29, 2024
Merged via the queue into fedimint:master with commit a597d53 Feb 29, 2024
20 checks passed
@elsirion elsirion deleted the 2024-02-forgiving-meta branch February 29, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants