-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 IPAddr prefix information missing when write to cache in msgpack serializer #50742
Conversation
packer: method(:write_ipaddr), | ||
unpacker: method(:read_ipaddr), | ||
recursive: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that we can't just change the serialization of a type now that the first version was released, as previous payload wouldn't be readable, and old code wouldn't be able to read new payload (cc @jonathanhefner that's the kind of stuff I was worried about :/)
So now we need to define a new IPAddr
type, and conditionally enable it, like we do in Paquito
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you are right. We should consider backward compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write the single string "#{ipaddr.to_s}/#{ipaddr.prefix}"
as single packer write, and unpacker back to :new
.
I think this way would keep the compatibility, but what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okey, did it without deprecation system.
Fortunately, IPAddr.new
can be compatible with or without prefixes(netmask).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it's not needed for backward compatibility, but what about forward compatibility? We unfortunately need both to allow for smooth upgrades.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I see the unpack
is unchanged, so we're good.
d0f1676
to
f47f92b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the pull request!
The current behavior was derived from IPAddr#as_json
, which also does not account for prefix
:
rails/activesupport/lib/active_support/core_ext/object/json.rb
Lines 236 to 240 in 0ecfbe2
class IPAddr # :nodoc: | |
def as_json(options = nil) | |
to_s | |
end | |
end |
However, MessagePack can roundtrip IPAddr
whereas JSON can't, so I think it's reasonable to support prefix
. 👍
Also, would you mind adding a CHANGELOG entry?
@jonathanhefner |
…serializer * Save cache size by omit the prefix if unnecessary * rename to straightforward naming. * check the prefix directly instead of inspect * Remove unused helper method * add to changelog Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
d9bf64e
to
3815171
Compare
I pushed a commit to tweak the CHANGELOG entry a bit and to squash the commits. Thank you, @r-plus! 📦 |
Motivation / Background
This Pull Request has been created because we notice the msgpack serializer missing the prefix(netmask) data of IPAddr object when dump.
Detail
This Pull Request fixed the missing prefix(netmask) data of IPAddr object when dumping by msgpack serializer.
Additional information
to_s
is not contains prefix(netmask) data.So
to_s
missing the prefix(netmask) data when dump/load by msgpack serializer.IPAddr object assertion
IPAddr instance equal assertion is not accurate to assert same data. This is reason why I use
inspect
for test.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]