Big int doesn't work well with JavaScript #8689
Unanswered
dongyuzheng
asked this question in
Potential Issue
Replies: 1 comment 2 replies
-
Related...
Some numbers for reference...
Anyways. Yes - the answer in that case is correct - if there's no need for numeric calculations and you're using that field as a PK, then a It's not obvious exactly if/what we should do about this in REST framework itself. Particularly without breaking backwards compat. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Because JS numbers suffer from FPE.
Take this big integer ID for example:
The returned ID is correct in the response json, but JS cannot load it properly.
This leads to nasty bugs.
The solution is to make the id into a
serializers.CharField()
: https://stackoverflow.com/questions/72943702/using-bigautofield-pk-from-drf-in-javascript ... but this took longer than it should've to debug and could've been more disasterous.Thoughts on "how to auto handle or warn the user"? E.g., "if field is bigint and number might suffer from FPE: error until user sets REST_FRAMEWORK_NO_ERROR_BIGINT_JS_FPE"
Additional tags: int64 bigint pk id fpe "wrong value"
Beta Was this translation helpful? Give feedback.
All reactions