Opened 6 years ago

Closed 4 years ago

#18255 closed Bug (fixed)

Inconsistent data type for BigIntegerField after calling full_clean()

Reported by: anonymous Owned by: adamduren
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords:
Cc: Areski Belaid Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no



class MyModel(Model):
    big = BigIntegerField()

    def full_clean(self):
        print type(self.big)
        super(MyModel, self).full_clean()
        print type(self.big)

When saving the model I get:

<type 'long'>
<type 'int'>

This means that full_clean() somehow converts the long to int. On the other hand, when getting the model from the database (MySQL in my case), the output of type(my_model.big) will be long again. From a user point of view this behavior is inconsistent and confusing.

Change History (10)

comment:1 Changed 6 years ago by anonymous

Version: 1.31.4

Also applies to Django 1.4

comment:2 Changed 6 years ago by Claude Paroz

Could you provide a use case where this behaviour might lead to a bug?

comment:3 Changed 6 years ago by anonymous

Use case: In my particular environment we have to check for data types in a custom clean() method in every model. Example code:

my_m = MyModel()
my_m.big = 2L

my_m2 = MyModel()
my_m2.big = my_m.big #raises ValidationError, because an integer was provided

On the other hand tis code works without a validation error:

my_m = MyModel.objects.get(id=1)
my_m2 = MyModel()
my_m2.big = my_m.big

comment:4 Changed 6 years ago by Jannis Leidel

Triage Stage: UnreviewedAccepted

comment:5 Changed 5 years ago by adamduren

Owner: changed from nobody to adamduren
Status: newassigned

comment:6 Changed 5 years ago by adamduren

Has patch: set

Fixed and tests written, pull request

comment:7 Changed 5 years ago by Claude Paroz

Patch needs improvement: set

The patch doesn't account for Python 3 (where long type doesn't exist).

comment:8 Changed 4 years ago by adamduren

I made the changes in pull request ​ as requested in pull request ​

comment:9 Changed 4 years ago by Areski Belaid

Cc: Areski Belaid added

This is already fixed on master, do we want to fix it on 1.4 or simply mark this ticket as wontfix?

comment:10 Changed 4 years ago by Tim Graham

Resolution: fixed
Status: assignedclosed

Per our supported versions policy, 1.4 is only receiving security fixes so we can close this. Thank-you for triaging.

Note: See TracTickets for help on using tickets.
Back to Top