From ed7a808ee88091c386ed531ca022d76013a3d314 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 18 Dec 2021 19:29:38 -0800 Subject: [PATCH] Allow for integer values larger than 32-bits (#137) * style: apply ignores to all migrations * feat: support 64-bit integers * doc: update changelog * test: add test for bigger than 32-bit integer --- CHANGELOG.md | 2 ++ eav/migrations/0007_alter_value_value_int.py | 17 +++++++++++++++++ eav/models.py | 2 +- setup.cfg | 4 +++- tests/test_attributes.py | 10 ++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 eav/migrations/0007_alter_value_value_int.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fd496..7b555e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ We follow [Semantic Versions](https://semver.org/) starting at the `0.14.0` rele ### Features +- Adds 64-bit support for `Value.value_int` + ### Bug Fixes ### Misc diff --git a/eav/migrations/0007_alter_value_value_int.py b/eav/migrations/0007_alter_value_value_int.py new file mode 100644 index 0000000..94239ee --- /dev/null +++ b/eav/migrations/0007_alter_value_value_int.py @@ -0,0 +1,17 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + """Convert Value.value_int to BigInteger.""" + + dependencies = [ + ('eav', '0006_add_entity_uuid'), + ] + + operations = [ + migrations.AlterField( + model_name='value', + name='value_int', + field=models.BigIntegerField(blank=True, null=True), + ), + ] diff --git a/eav/models.py b/eav/models.py index 7243a22..76f56eb 100644 --- a/eav/models.py +++ b/eav/models.py @@ -443,7 +443,7 @@ class Value(models.Model): # noqa: WPS110 value_csv = CSVField(blank=True, null=True) value_date = models.DateTimeField(blank=True, null=True) value_float = models.FloatField(blank=True, null=True) - value_int = models.IntegerField(blank=True, null=True) + value_int = models.BigIntegerField(blank=True, null=True) value_text = models.TextField(blank=True, null=True) value_json = JSONField( diff --git a/setup.cfg b/setup.cfg index ab3e3f5..02b6569 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,7 +39,9 @@ ignore = DAR203 per-file-ignores = - test_project/migrations/*.py: N806, WPS102, WPS114 + # Allow to have magic numbers inside migrations and wrong module names: + */migrations/*.py: WPS102, WPS114, WPS432 + # Allow `__init__.py` with logic for configuration: test_project/settings.py: S105, WPS226, WPS407 tests/test_*.py: N806, S101, S404, S603, S607, WPS118, WPS226, WPS432, WPS442 diff --git a/tests/test_attributes.py b/tests/test_attributes.py index 011f311..800b610 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -99,3 +99,13 @@ class Attributes(TestCase): v1 = Value.objects.filter(entity_uuid=d1.pk).first() assert isinstance(repr(v1), str) assert isinstance(str(v1), str) + + def test_big_integer(self): + """Tests an integer larger than 32-bit a value.""" + big_num = 3147483647 + patient = Patient.objects.create(name='Jon') + patient.eav.age = big_num + + patient.save() + + assert patient.eav.age == big_num