-
-
Notifications
You must be signed in to change notification settings - Fork 827
Regression? deserialize_u64
(etc.) no longer allow visitors with non-numeric branches
#1125
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
Comments
This code has absolutely zero reason to be calling `deserialize_i32`, and doing so triggers serde-rs/serde#1125 Let's not do that.
This is the same issue as paritytech/jsonrpc#222 which was caused by serde-rs/json#389. In that case it was easily fixed by calling A hacky way to sort of fix your immediate issue may be to detect https://docs.serde.rs/serde/de/trait.Deserializer.html#method.is_human_readable and switch between |
Thanks for the detailed report, and I am sorry about the breakage. This changed in serde_json 1.0.8 for what I believe is a justifiable reason (explained in the link). The workaround is to use If there is a use case we aren't hitting, I would be open to supporting it better. For example we could add a cfg in serde_json that ~doubles the compile time of every Deserialize impl in exchange for always faithfully calling the right Visitor method when your hint is wrong. Is that something you might want in bigml? |
Ah, thank you! I apparently badly misunderstood what "hint" meant in all the docs. I figured that it meant, "When you have no type information (such as for a binary format), here's the type to assume by default. But if you do have type information in the format, call the visitor." And indeed, for a surprising number of combinations, it may still actually work like that? Anyway, I wrote a lot of code against
...and most of this seems to be working fine, last I checked, even though it was supposedly broken in 1.0.8. Now, the good news is that I can probably fix most of this code in a few hours. But just as a data point from one user of the library, this (personally, subjectively) felt like it was either:
Maybe it would be worth calling this out in the docs? That certainly would have helped me avoid this mistake. I don't think a code change is necessary here—I can certainly track down and fix most of the affected code without too much hassle, and Anyway, thank you very much for your followup and your clarifications! |
The discussion at serde-rs/serde#1125 suggests that any vistor which might take multiple types should always use `deserialize_any`. This seems like either an API or a documentation issue to me, and I'm going to update other libraries as well.
I agree that "hint" is poorly explained in the documentation. I filed #1128 to follow up. The word was intended to mean something that is allowed to be ignored, but is not allowed to be wrong. This is the same meaning of "hint" as in "What is the capital city of France? Hint: the name begins with Z." I also filed #1127 to track your idea of enforcing this in the Deserializer API by having different Deserializer methods take different Visitor traits. Deserialize impls that require type information from the input should be using deserialize_any. Going forward, I will avoid making similar changes in other formats except in a breaking release. |
Great, thank you! I've fixed most of my affected code, and you can close this issue if you want. |
We make heavy use of
serde
at work, and it's been a reliable workhorse for a long time. Thank you!When upgrading from
serde
1.0.17 to 1.0.24, our open sourcebigml
bindings hit a regression in how the numericdeserialize_$NUMERIC_TYPE
handlers work.Here's some example code (playground):
What we expected: Before, this code would parse the second input
"10"
as a number, using the visitor.What happens: We get the error:
Probable cause: This code looks suspicious (from the debugger):
Here, on line 260, it looks like if we don't see
[-0-9]
, the code immediately gives up without giving the visitor a shot at handle the alternative types.But if we consult the docs for
deserialize_u64
, they say:In the past, this was treated strictly as a hint, but now it seems to enforce a numeric type.
Thank you for looking into this!
The text was updated successfully, but these errors were encountered: