Opened 3 years ago

Closed 3 years ago

Last modified 3 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 3 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 3 years ago by bpeschier

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 3 years ago by bigkevmcd

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

comment:2 Changed 3 years ago by bigkevmcd

  • Has patch set
  • Owner changed from nobody to bigkevmcd

comment:3 follow-up: Changed 3 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 3 years ago by julien

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

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 3 years ago by julien

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