#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


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 22 months ago by bmispelon

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

Good catch, thanks.

comment:2 Changed 22 months ago by mjtamlyn

Maths is hard.

comment:3 Changed 22 months ago by Marc Tamlyn <marc.tamlyn@…>

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

In 16f3a6a4c7bab11644d11c2be029374e5095cb56:

Fixed #21865 -- Incorrect signs in documented example.

Maths is hard.

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