Opened 6 years ago

Closed 6 years ago

#29772 closed New feature (fixed)

SimpleLazyObject doesn't implement __gt__ / __lt__

Reported by: Javier Buzzi Owned by: nobody
Component: Core (Other) Version: dev
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 by Simon Charette, 6 years ago

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

comment:2 by Javier Buzzi, 6 years ago

@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 by Simon Charette, 6 years ago

Triage Stage: AcceptedReady for checkin
Version: 2.1master

comment:4 by Tim Graham <timograham@…>, 6 years ago

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