Opened 3 years ago

Closed 3 years ago

#21788 closed Uncategorized (wontfix)

Wrong fields order after defer

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords: defer models
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

postgresql view:

CREATE VIEW test_view AS
    SELECT md5(g.*::text) as hash,
    g.g AS num FROM generate_series(1,4) g;

query result:

hash

num

c4ca4238a0b923820dcc509a6f75849b

1

c81e728d9d4c2f636f067f89cc14862c

2

eccbc87e4b5ce2fe28308fd9f2a7baf3

3

a87ff679a2f3e71d9181a67b7542122c

4

django model:

class TestView(models.Model):
    id = models.CharField(primary_key=True, max_length=32, db_column='hash')
    hash = models.CharField(max_length=32, db_column='hash')
    num = models.IntegerField(db_column='num')

    class Meta:
        db_table = 'test_view'

ipython test:

In [1]: from public_api.models import TestView                                                                                                                         

In [2]: TestView.objects.all()[0].num                                                                                                                                  
Out[2]: 1

In [3]: TestView.objects.defer('hash').all()[0].num                                                                                                                    
Out[3]: u'c4ca4238a0b923820dcc509a6f75849b'

Change History (2)

comment:1 Changed 3 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Reproduces with Django 1.6 and 1.6.1

comment:2 Changed 3 years ago by Anssi Kääriäinen

Resolution: wontfix
Status: newclosed

The problem is almost certainly in having db_column "hash" two times in the model definition. Drop the id field and set the hast field as primary key, or add id column to the view.

You shouldn't use two different fields with the same db column, so closing as wontfix.

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