Skip to content

Add optional support to serialize BigInteger to string - #9775

Merged
auvipy merged 8 commits into
encode:mainfrom
HoodyH:bigint-coerce
Dec 2, 2025
Merged

auvipy merged 8 commits into
encode:mainfrom
HoodyH:bigint-coerce

Conversation

@HoodyH

@HoodyH HoodyH commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

Fixing Bigint coerce to string missing

Creates a new type BigIntegerField to map django.models.BigIntegerField and solve the problem

Fix #9733

@auvipy auvipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@HoodyH

HoodyH commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

Any news?

@auvipy auvipy added this to the 3.17 milestone Sep 22, 2025
Comment thread docs/api-guide/fields.md Resolved
Comment thread docs/api-guide/settings.md Resolved
Comment thread rest_framework/serializers.py Resolved
Comment thread tests/test_fields.py Resolved
- typo fix
- value test fix
- import order fix

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new BigIntegerField serializer field to properly handle Django's BigIntegerField and BigAutoField model fields, addressing issue #9733. Previously, these fields were incorrectly mapped to the standard IntegerField serializer.

Key Changes:

  • Introduces BigIntegerField class that extends IntegerField with optional string coercion for large integers
  • Adds COERCE_BIGINT_TO_STRING setting (default: False) to control output format
  • Updates model field mappings to use BigIntegerField for BigIntegerField and BigAutoField

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
rest_framework/fields.py Implements new BigIntegerField class with coerce_to_string parameter and custom error messages
rest_framework/serializers.py Imports BigIntegerField and updates serializer_field_mapping to map Django's BigIntegerField and BigAutoField to the new field type
rest_framework/settings.py Adds COERCE_BIGINT_TO_STRING configuration setting with default value of False
docs/api-guide/fields.md Documents the new BigIntegerField with its signature and parameters
docs/api-guide/settings.md Documents the COERCE_BIGINT_TO_STRING setting and its behavior
tests/test_fields.py Adds comprehensive test cases for BigIntegerField including validation, min/max constraints, and string coercion
tests/test_model_serializer.py Updates expected serializer representation test to expect BigIntegerField instead of IntegerField

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_fields.py Resolved
Comment thread docs/api-guide/fields.md Resolved
Comment thread docs/api-guide/fields.md Resolved
Comment thread docs/api-guide/fields.md Resolved
Comment thread docs/api-guide/settings.md Resolved
auvipy and others added 3 commits November 11, 2025 13:34
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread rest_framework/fields.py Resolved

@peterthomassen peterthomassen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Thank you for this contribution.

@auvipy
auvipy requested a review from browniebroke December 2, 2025 06:13
@auvipy
auvipy merged commit f9f10e0 into encode:main Dec 2, 2025
@browniebroke browniebroke changed the title Bigint coerce to string Add optional support to serialize BigInteger to string Feb 11, 2026
HosseinSayyedMousavi pushed a commit to HosseinSayyedMousavi/django-rest-framework that referenced this pull request Oct 8, 2026
* feat: BinIntegerField and COERCE_BIGINT_TO_STRING setting, bigint now can have string api representation

* fix: wrong import location in serializers.py

* feat: updated with changes requests
- typo fix
- value test fix
- import order fix

* Update tests/test_fields.py

* Update docs/api-guide/fields.md

* Update docs/api-guide/fields.md



* refactor: changed BigIntegerField.to_representation simplified + calling super

---------

Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Bigint coerce to string missing

5 participants