Opened 12 years ago

Closed 10 years ago

#18255 closed Bug (fixed)

Inconsistent data type for BigIntegerField after calling full_clean()

Reported by: anonymous Owned by: Adam Duren
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

Description

Example:

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 by anonymous, 12 years ago

Version: 1.31.4

Also applies to Django 1.4

comment:2 by Claude Paroz, 12 years ago

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

comment:3 by anonymous, 12 years ago

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_m.save()

my_m2 = MyModel()
my_m2.big = my_m.big
my_m2.save() #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
my_m2.save()

comment:4 by Jannis Leidel, 12 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Adam Duren, 11 years ago

Owner: changed from nobody to Adam Duren
Status: newassigned

comment:6 by Adam Duren, 11 years ago

Has patch: set

Fixed and tests written, pull request https://github.com/django/django/pull/810

comment:7 by Claude Paroz, 11 years ago

Patch needs improvement: set

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

comment:8 by Adam Duren, 10 years ago

I made the changes in pull request ​https://github.com/django/django/pull/2202 as requested in pull request ​https://github.com/django/django/pull/810.

comment:9 by Areski Belaid, 10 years ago

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 by Tim Graham, 10 years ago

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