Opened 5 years ago

Closed 5 years ago

Last modified 5 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 5 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 Changed 5 years ago by Bas Peschier

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

Changed 5 years ago by bigkevmcd

Attachment: bug_17429.patch added

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

comment:2 Changed 5 years ago by bigkevmcd

Has patch: set
Owner: changed from nobody to bigkevmcd

comment:3 Changed 5 years ago by 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.

comment:4 Changed 5 years ago by Julien Phalip

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.

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

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