Opened 4 years ago

Closed 4 years ago

#21865 closed Uncategorized (fixed)

Greater than/Less than symbols incorrect in 1.7 alpha-1 documentation for Custom Lookups

Reported by:… Owned by: nobody
Component: Documentation Version: 1.7-alpha-1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


The documentation for 1.7-alpha-1 gives an example for writing a custom lookup to generate the following SQL:

SELECT .. WHERE "experiments"."change" < 27 AND "experiments"."change" > -27
from django.db.models import Lookup

class AbsoluteValueLessThan(Lookup):
    lookup_name = 'lt'

    def as_sql(self, qn, connection):
        lhs, lhs_params = qn.compile(self.lhs.lhs)
        rhs, rhs_params = self.process_rhs(qn, connection)
        params = lhs_params + rhs_params + lhs_params + rhs_params
        return '%s > %s AND %s < -%s' % (lhs, rhs, lhs, rhs), params


The return statement has the < and > symbols incorrectly reversed to create

"experiments"."change" > 27 AND "experiments"."change" < -27


Change History (3)

comment:1 Changed 4 years ago by Baptiste Mispelon

Triage Stage: UnreviewedAccepted

Good catch, thanks.

comment:2 Changed 4 years ago by Marc Tamlyn

Maths is hard.

comment:3 Changed 4 years ago by Marc Tamlyn <marc.tamlyn@…>

Resolution: fixed
Status: newclosed

In 16f3a6a4c7bab11644d11c2be029374e5095cb56:

Fixed #21865 -- Incorrect signs in documented example.

Maths is hard.

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