Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#18324 closed Bug (worksforme)

QuerySet values ​​method fails

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

Description (last modified by lukeplant)

class SomeModel(models.Model):

    field1 = models.CharField(max_length=100, blank=True, null=True, default='')
    field2 = models.CharField(max_length=100, blank=True, null=True, default='')
    field3 = models.CharField(max_length=100, blank=True, null=True, default='')

    class Meta:
        db_table = 'some_model'
        ordering = ['field1'] # Caused by this line
        #
        # SomeModel.objects.values('field1') # sql: select field1, field2, field3, from some_model
        #

Change History (3)

comment:1 Changed 3 years ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

I can't reproduce this on 1.4. This is the used test case:
https://github.com/akaariai/django/commit/fa76c9ee0d9847ea357b8b1be7f3c786255713f5

And here is the generated SQL

SELECT "some_model"."field1" FROM "some_model" ORDER BY "some_model"."field1" ASC

which looks correct to me.

comment:2 Changed 3 years ago by lukeplant

  • Description modified (diff)

comment:3 in reply to: ↑ description Changed 3 years ago by anonymous

Replying to anonymous:

class SomeModel(models.Model):

    field1 = models.CharField(max_length=100, blank=True, null=True, default='')
    field2 = models.CharField(max_length=100, blank=True, null=True, default='')
    field3 = models.CharField(max_length=100, blank=True, null=True, default='')
    sequence = models.IntegerField(default=0)
    class Meta:
        db_table = 'some_model'
        ordering = ['field1', 'sequence'] # Caused by this line
        #
        # SomeModel.objects.values('field1').distinct() # sql: SELECT DISTINCT "some_model"."field1", "some_model"."sequence" FROM "some_model" ORDER BY "some_model"."field1" ASC, "some_model"."sequence" ASC
        #

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