Opened 4 years ago

Closed 4 years ago

#19405 closed Bug (duplicate)

Long integers cause DatabaseError when submitting ModelForm

Reported by: Daniil Ryzhkov Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords: form, admin, DatabaseError, ModelForm
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Let's say there is a model:

class TestModel(models.Model):
    test_field = models.IntegerField()

And ModelForm (instread of this step you can just register model in admin):

class TestForm(forms.ModelForm):

    class Meta:
        model = TestModel

And view:

def test_view(request):
    if form.is_valid():

When from is submitted Django returns "DatabaseError: current transaction is aborted, commands ignored until end of transaction block" if submitted integer is above 2147483647 (which is database maximum value for integer). This affects both contrib.admin generated form and ModelForm.
This was tested on Django 1.4 with Debian Squeeze and PostgreSQL 9.1 aboard.

Change History (2)

comment:1 Changed 4 years ago by Daniil Ryzhkov

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: Long integers causing DatabaseError when submitting ModelFormLong integers cause DatabaseError when submitting ModelForm

comment:2 Changed 4 years ago by Claude Paroz

Resolution: duplicate
Status: newclosed

The problem is that the maximum value is database-dependent (See #16747). You can initialize IntegerField with max_value to prevent this error.

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