[Django] #26053: makemigrations generates a wrong type for a DurationField column on postgresql

9 views
Skip to first unread message

Django

unread,
Jan 7, 2016, 10:01:23 AM1/7/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) | Keywords: makemigrations,
Severity: Normal | DurationField, postgresql, psycopg2
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
'''Dependencies''':
- Django version : 1.9.1
- PostgreSQL version : "PostgreSQL 9.4.4 on x86_64-unknown-linux-gnu,
compiled by gcc (Ubuntu 4.9.1-16ubuntu6) 4.9.1, 64-bit"
- DB conf :
{{{
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'test',
'USER': 'test',
'PASSWORD': 'test',
'HOST': 'localhost',
'PORT': '',
},
}
}}}

'''Following those steps:'''
1 - creating a minimal model example including a DurationField
{{{
class Foo(models.Model):
bar = models.DurationField()
}}}

2 - migrate the new model
{{{
$ python manage.py makemigrations AppName
$ python manage.py migrate
}}}

3 - then check the type of the 'bar' DB column related to the 'bar'
DurationField on the 'appname_foo' generated table
{{{
\d appname_foo
}}}

=> The datatype associated to the bar column is not interval as expected
but float

--
Ticket URL: <https://code.djangoproject.com/ticket/26053>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 7, 2016, 11:17:57 AM1/7/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Hi benjellounayoub,

I couldn't reproduce against PostgreSQL 9.3 and 9.3 on Ubuntu with Django
1.9.1 and master using a [https://github.com/charettes/django-
ticketing/commit/b5ddf8554d41d23474f48ae3bf156af5f0f0b9ca similar test
application].

{{{
\d ticket_26053_foo;
Table "public.ticket_26053_foo"
Column | Type | Modifiers
--------+----------+---------------------------------------------------------------
id | integer | not null default
nextval('ticket_26053_foo_id_seq'::regclass)
bar | interval | not null
Indexes:
"ticket_26053_foo_pkey" PRIMARY KEY, btree (id)
}}}

Can you confirm the generated migration's `CreateModel` operation used a
`models.DurationField()` for its `'bar'` field?

--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:1>

Django

unread,
Jan 7, 2016, 7:07:30 PM1/7/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by benjellounayoub):

No, unfortunately it's not the case

For the following model


{{{
class Foo(models.Model):
bar = models.DurationField()
}}}

I have the following CreateModel in the generated migrations
{{{
...
operations = [
migrations.CreateModel(
name='Foo',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('bar', models.FloatField(blank=True, default=0,
null=True)),
],
...
}}}

Can you test it with the 9.4 postgreSQL version instead of the 9.3 ? it's
maybe related to this part ...

--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:2>

Django

unread,
Jan 7, 2016, 7:23:19 PM1/7/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.9
(models, ORM) | Resolution:
Severity: Normal | worksforme

Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => worksforme


Comment:

Can you double check you didn't make a mistake (i.e. delete the migration
and re-run `makemigrations`)? It's unthinkable to me that Django would
transform `DurationField()` to `FloatField(blank=True, default=0,
null=True))`.

--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:3>

Django

unread,
Jan 8, 2016, 4:25:27 AM1/8/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.9
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by benjellounayoub):

Sorry but there is no mistake at all, i can reproduce the issue again and
again

--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:4>

Django

unread,
Jan 8, 2016, 4:25:41 AM1/8/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:

Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by benjellounayoub):

* status: closed => new
* resolution: worksforme =>


--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:5>

Django

unread,
Jan 8, 2016, 4:33:25 AM1/8/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by benjellounayoub):

Replying to [comment:1 charettes]:

I think you are using the Django's version 1.10.dev for your test and not
the 1.9

> Hi benjellounayoub,
>
> I couldn't reproduce against PostgreSQL 9.3 and 9.3 on Ubuntu with
Django 1.9.1 and master using a [https://github.com/charettes/django-
ticketing/commit/b5ddf8554d41d23474f48ae3bf156af5f0f0b9ca similar test
application].
>
> {{{
> \d ticket_26053_foo;
> Table "public.ticket_26053_foo"
> Column | Type | Modifiers
>
--------+----------+---------------------------------------------------------------
> id | integer | not null default
nextval('ticket_26053_foo_id_seq'::regclass)
> bar | interval | not null
> Indexes:
> "ticket_26053_foo_pkey" PRIMARY KEY, btree (id)
> }}}
>
> Can you confirm the generated migration's `CreateModel` operation used a
`models.DurationField()` for its `'bar'` field?

--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:6>

Django

unread,
Jan 8, 2016, 6:58:21 AM1/8/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

Could you please provide a sample project with steps to reproduce it? For
the provided model, I'm still seeing this for the 1.9 branch:
{{{


migrations.CreateModel(
name='Foo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True,
serialize=False, verbose_name='ID')),

('bar', models.DurationField()),
],
),
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:7>

Django

unread,
Jan 8, 2016, 1:14:55 PM1/8/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by charettes):

@benjellounayoub, the migration I commited was generated with the master
branch because I first reproduced against 1.9 and tried against master to
see if it was fixed.

I managed to reproduce against Django [https://asciinema.org/a/33254
again]. Please let me know if I missed something.

Are you sure you don't have any third party app that might have interfered
and you are really using the `django.db.models.DurationField`?

--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:8>

Django

unread,
Jan 8, 2016, 6:17:09 PM1/8/16
to django-...@googlegroups.com
#26053: makemigrations generates a wrong type for a DurationField column on
postgresql
-------------------------------------+-------------------------------------
Reporter: benjellounayoub | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.9
(models, ORM) | Resolution:
Severity: Normal | worksforme

Keywords: makemigrations, | Triage Stage:
DurationField, postgresql, | Unreviewed
psycopg2 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => worksforme


--
Ticket URL: <https://code.djangoproject.com/ticket/26053#comment:9>

Reply all
Reply to author
Forward
0 new messages