Opened 3 years ago

Closed 10 months 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 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 Changed 3 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.3 to 1.4

Also applies to Django 1.4

comment:2 Changed 3 years ago by claudep

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

comment:3 Changed 3 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_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 Changed 3 years ago by jezdez

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 2 years ago by adamduren

  • Owner changed from nobody to adamduren
  • Status changed from new to assigned

comment:6 Changed 2 years ago by adamduren

  • Has patch set

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

comment:7 Changed 2 years ago by claudep

  • Patch needs improvement set

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

comment:8 Changed 18 months ago by adamduren

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 Changed 10 months ago by areski

  • Cc areski 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 10 months ago by timgraham

  • Resolution set to fixed
  • Status changed from assigned to closed

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