Skip to content
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

if model filed type is BigInt, import excel data error #788

Closed
luohaifenglight opened this issue Jun 8, 2018 · 5 comments
Closed

if model filed type is BigInt, import excel data error #788

luohaifenglight opened this issue Jun 8, 2018 · 5 comments
Labels

Comments

@luohaifenglight
Copy link

if model filed type is BigInt, such as 163371428940853127, to be convert 163371428940853120 overflow.

@bmihelac
Copy link
Member

Hi @luohaifenglight and thanks for opening this issue. Can you add failing test case?

@stale
Copy link

stale bot commented Feb 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale bot label Feb 11, 2019
@stale stale bot closed this as completed Feb 18, 2019
@josx
Copy link
Contributor

josx commented Nov 19, 2021

Same here!
Failing case:

diff --git a/tests/core/tests/test_widgets.py b/tests/core/tests/test_widgets.py
index 7969961..5d41b58 100644
--- a/tests/core/tests/test_widgets.py
+++ b/tests/core/tests/test_widgets.py
@@ -253,11 +253,11 @@ class DecimalWidgetTest(TestCase):
class IntegerWidgetTest(TestCase):

def setUp(self):
-        self.value = 0
+        self.value = 163371428940853127
self.widget = widgets.IntegerWidget()

def test_clean_integer_zero(self):
-        self.assertEqual(self.widget.clean(0), self.value)
+        self.assertEqual(self.widget.clean(163371428940853127), self.value)

Then make test, result:

PYTHONPATH=".:tests:" django-admin test core --settings=settings
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..........................................................................................................................................................s...............................................................................................................FF.............................s
======================================================================
FAIL: test_clean_integer_zero (core.tests.test_widgets.IntegerWidgetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django-import-export/tests/core/tests/test_widgets.py", line 260, in test_clean_integer_zero
self.assertEqual(self.widget.clean(163371428940853127), self.value)
AssertionError: 163371428940853120 != 163371428940853127

@josx
Copy link
Contributor

josx commented Nov 19, 2021

This is the problem

>>> int(float(163371428940853127))
163371428940853120

https://github.com/django-import-export/django-import-export/blob/main/import_export/widgets.py#L88

@josx
Copy link
Contributor

josx commented Nov 19, 2021

I will do a PR with this fix:
Tomorrow I Will do a PR using decimal instead of float:

>>> import decimal
>>> int(decimal.Decimal(163371428940853127))
163371428940853127

josx added a commit to josx/django-import-export that referenced this issue Nov 19, 2021
Signed-off-by: José Luis Di Biase <josx@interorganic.com.ar>
josx added a commit to josx/django-import-export that referenced this issue Nov 19, 2021
Signed-off-by: José Luis Di Biase <josx@interorganic.com.ar>
matthewhegarty added a commit that referenced this issue Nov 19, 2021
Big integer support for Integer widget (#788)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants