Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17429 closed Bug (fixed)

if ordering = None incorrect result

Reported by: self@… Owned by: bigkevmcd
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Model:

Code highlighting:

class SomeModel(models.Model):
    value = models.DecimalField(max_digits=5, decimal_places=2)
    
    class Meta:
        ordering = None

In [4]: SomeModel.objects.create(value=1)
Out[4]: <SomeModel: SomeModel object>

In [5]:  SomeModel.objects.create(value=2)
Out[5]: <SomeModel: SomeModel object>

In [6]: SomeModel.objects.count()
Out[6]: 2

In [7]: SomeModel.objects.all()
Out[7]: []

Attachments (1)

bug_17429.patch (1.3 KB ) - added by bigkevmcd 13 years ago.
Simple test and patch for this (it was throwing an error because None is not iterable)

Download all attachments as: .zip

Change History (6)

comment:1 by Bas Peschier, 13 years ago

Triage Stage: UnreviewedAccepted

by bigkevmcd, 13 years ago

Attachment: bug_17429.patch added

Simple test and patch for this (it was throwing an error because None is not iterable)

comment:2 by bigkevmcd, 13 years ago

Has patch: set
Owner: changed from nobody to bigkevmcd

comment:3 by anonymous, 13 years ago

Would it be better to set ordering to () if ordering is None in Model setup? That way this same bug will not raise its head in other places of the code.

comment:4 by Julien Phalip, 13 years ago

Resolution: fixed
Status: newclosed

In [17334]:

Fixed #17429 -- Ensured that Meta.ordering=None works the same if it were an empty list. Thanks to self[at]dicos[dot]ru for the report and to bigkevmcd for the patch.

in reply to:  3 comment:5 by Julien Phalip, 13 years ago

Replying to anonymous:

Would it be better to set ordering to () if ordering is None in Model setup? That way this same bug will not raise its head in other places of the code.

I think it's best to at least put some safe-guarding in SQLCompiler.get_ordering() as that was done in [17334]. If you see any place in the code where more safe-guarding is required, please open a new ticket. Thanks!

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