Code

Opened 3 months ago

Closed 3 months 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'

Attachments (0)

Change History (2)

comment:1 Changed 3 months 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 months ago by akaariai

  • Resolution set to wontfix
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.