Opened 11 years ago

Closed 11 years ago

#21865 closed Uncategorized (fixed)

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

Reported by: john.young.dev@… 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

Description

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

AbsoluteValue.register_lookup(AbsoluteValueLessThan)

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

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

.

Change History (3)

comment:1 by Baptiste Mispelon, 11 years ago

Triage Stage: UnreviewedAccepted

Good catch, thanks.

comment:2 by Marc Tamlyn, 11 years ago

Maths is hard.

comment:3 by Marc Tamlyn <marc.tamlyn@…>, 11 years ago

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