-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Bigint coerce to string #9775
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
base: main
Are you sure you want to change the base?
Bigint coerce to string #9775
Changes from 1 commit
62335cf
c831093
f6b53d8
3b89b8e
aeb9b73
1c3b1ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -921,6 +921,36 @@ def to_representation(self, value): | |
| return int(value) | ||
|
|
||
|
|
||
| class BigIntegerField(IntegerField): | ||
|
|
||
| default_error_messages = { | ||
| 'invalid': _('A valid biginteger is required.'), | ||
| 'max_value': _('Ensure this value is less than or equal to {max_value}.'), | ||
| 'min_value': _('Ensure this value is greater than or equal to {min_value}.'), | ||
| 'max_string_length': _('String value too large.') | ||
| } | ||
|
|
||
| def __init__(self, coerce_to_string=None, **kwargs): | ||
| super().__init__(**kwargs) | ||
|
|
||
| if coerce_to_string is not None: | ||
| self.coerce_to_string = coerce_to_string | ||
|
|
||
| def to_representation(self, value): | ||
| coerce_to_string = getattr(self, 'coerce_to_string', api_settings.COERCE_BIGINT_TO_STRING) | ||
|
|
||
| if value is None: | ||
| if coerce_to_string: | ||
| return '' | ||
| else: | ||
| return None | ||
|
|
||
| if coerce_to_string: | ||
| return str(value) | ||
| else: | ||
| return int(value) | ||
|
Comment on lines
+940
to
+951
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we treat the A more consistent approach would be: if getattr(self, 'coerce_to_string', api_settings.COERCE_BIGINT_TO_STRING):
return '' if value is None else str(value)
return super().to_representation(value)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... with this change, If so, do we also want it when coerce_to_string = getattr(self, 'coerce_to_string', api_settings.COERCE_BIGINT_TO_STRING)
return str(value) if coerce_to_string else int(value) |
||
|
|
||
|
|
||
| class FloatField(Field): | ||
| default_error_messages = { | ||
| 'invalid': _('A valid number is required.'), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.