#29772 closed New feature (fixed)

SimpleLazyObject doesn't implement __gt__ / __lt__

Reported by: Javier Buzzi Owned by: nobody
Component: Core (Other) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Similar ticket: https://code.djangoproject.com/ticket/26287

I'm trying to implement this:

MinValueValidator(SimpleLazyObject(datetime.date.today))(datetime.date(2018, 9, 19))

The reason it doesn't work seems to be because __lt__ and __gt__ are not implemented in LazyObject.

When i make the following change:

class Simple(SimpleLazyObject):
     __lt__ = new_method_proxy(operator.lt)
     __gt__ = new_method_proxy(operator.gt)

MinValueValidator(Simple(datetime.date.today))(datetime.date(2018, 9, 17))
ValidationError: [u'Ensure this value is greater than or equal to 2018-09-19.']

I get my expected result.

This doesn't seem like an unreasonable ask.

Change History (4)

comment:1 Changed 23 months ago by Simon Charette

Component: UncategorizedCore (Other)
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

comment:2 Changed 23 months ago by Javier Buzzi

@Simon Charette Can this go into 2.0 or.. 1.x? If not i'll wait i suppose. This diff can be back ported without difficulty. Ps. i have PR: https://github.com/django/django/pull/10419 not sure where to put it.

comment:3 Changed 23 months ago by Simon Charette

Triage Stage: AcceptedReady for checkin
Version: 2.1master

comment:4 Changed 23 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In a0d63b0:

Fixed #29772 -- Made LazyObject proxy lt() and gt().

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