-
Notifications
You must be signed in to change notification settings - Fork 364
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
OverflowError on large long values #99
Comments
As designed. On 25 jul 2013, at 10:55, "ishirav" <notifications@github.commailto:notifications@github.com> wrote: Large long values cannot be encoded by ujson (cjson does not have the same problem). Example code: import ujson, cjson
— |
Well... this is a deviation from the JSON standard, which does not impose a limit on the length of integers. It's also a "landmine" that might blow up in a production system - because everything works when you test it with numbers that are small enough, but unexpectedly fails when somewhere, someone passes a very large number. I don't think it a good idea to keep this limitation in place, even if it's "as designed". Thanks! |
Wouldn't it be better to return SOME value instead of an error? For example it should be simple enough to convert the long to it's string representation and return that. Refactoring for a returned string is easier than refactoring to avoid presenting a long to the renderer. Is this possible? _Some context:_ I am trying to use ultrajson with a production system and as soon as I installed it all my JSON endpoints are dead with this error because we use longs as our Primary Key IDs on most of our models. So I would need to refactor ALL of my endpoints to try to avoid presenting a long to the renderer. This is a mess. I agree with @ishirav that this is not a good limitation, and I would say this limitation is arguably poor design if it was intended. |
@ethompsy, I think returning a string value when a number is expected is even worse than throwing an error, because you're hiding the problem and also changing the content of the JSON document. |
@ishirav, Is it worse than NOT supporting long integers? I use I think that ease of use should be a consideration when making these design decisions. I do think your point is still the most useful suggestion here: "this is a deviation from the JSON standard, which does not impose a limit on the length of integers". Sticking to agreed standards is one way to ensure ease of use. |
Finded some really strange bug > ujson.dumps({'params': [1, 18446744073709551616L], 'method': ''})
'{"params":[1,],"method":""}'
> ujson.dumps({'params': [1, 18446744073709551616L], 'test': ''})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: long too big to convert as you can see in first example encoder silently ignore LONG and return incorrect data, but in second example it raise error |
When I try to convert a dictionary to json, I get this error. I'm using ecc==0.0.1.dev8 Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32 from uuid import uuid4
from ecc.ecdh import ECDH
client = ECDH(private_key=int(uuid4().hex, 16), curve='secp521r1')
data = {
'private_key': client.private_key,
'public_key': client.public_key
}
print(ujson.dumps(data))
|
Large long values cannot be encoded by ujson (cjson does not have the same problem). Example code:
The text was updated successfully, but these errors were encountered: