You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using jsonschema-rs inside PostgreSQL via plpython3u. When I use PG's TRANSFORM FOR TYPE JSONB instead of python's json.loads(...) floats are converted to decimal.Decimal.
There could be multiple ways to approach this issue. The simplest one would be to utilize the arbitrary_precision feature of serde-json - in this case, any number will be parsed as a string. Roughly:
Enable this feature for the underlying Rust crate
Convert strings to some decimal representation (e.g. rust_decimal::Decimal) instead of using as_<type> convertors
Adapt the validation logic to work with decimal representation. For rust_decimal::Decimal many things will work out of the box, as it implements comparison (though, it might require some adaptation)
And it will hit performance for the common case (unless behind a feature flag) because it will use String in many cases where smaller types would work. Though, it is kind of a thing that needs to be implemented anyway to support working with large numbers without precision loss on the Rust side.
Answering your question
Is this something that needs to be supported in pyo3 first?
There is no requirement for this to be implemented on the pyo3 side. Though, we'll need to convert values manually :)
It might be also good to take a look at this issue first. Implementing it will allow us to use a specialized implementation for Python objects and maybe avoid unnecessary string conversions & using that abovementioned feature flag at all.
I'm using
jsonschema-rs
inside PostgreSQL viaplpython3u
. When I use PG'sTRANSFORM FOR TYPE JSONB
instead of python'sjson.loads(...)
floats are converted todecimal.Decimal
.This results in:
The error is thrown here:
https://github.com/Stranger6667/jsonschema-rs/blob/0515c955a484d0a33308c2ed8c0057c7f6fb84a1/bindings/python/src/ser.rs#L223-L226
Is it possible to support
Decimal
, too?Float is serialized like this:
https://github.com/Stranger6667/jsonschema-rs/blob/0515c955a484d0a33308c2ed8c0057c7f6fb84a1/bindings/python/src/ser.rs#L124-L126
Is this something that needs to be supported in
pyo3
first?The text was updated successfully, but these errors were encountered: