Opened 3 years ago

Closed 2 years ago

#26479 closed New feature (fixed)

Add "is not" comparison to the if template tag

Reported by: Alasdair Nicol Owned by: Alasdair Nicol
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

#26118 added the is comparison to the if template tag. We should add the is not comparison as well.

From a quick test, it seems that {% x is not None %} is currently evaluated as x is (not None), instead of x is not None.

Discussion on django-developers mailing list: https://groups.google.com/d/msg/django-developers/jYdYCAtHHdw/WJYNXqAzEwAJ

Change History (9)

comment:1 Changed 3 years ago by Alasdair Nicol

Owner: changed from nobody to Alasdair Nicol
Status: newassigned

comment:2 Changed 3 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:3 Changed 3 years ago by Alasdair Nicol

Has patch: set

comment:4 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In c16b9dd:

Fixed #26479 -- Added 'is not' operator to the if tag.

comment:5 Changed 3 years ago by Alasdair Nicol

Resolution: fixed
Status: closednew

Re-opening because I think we should we document (and add tests) for when either or both of the variables are not in the template context.

As an aside, I can't see any tests for the != operator in the test_if.py. If I haven't overlooked them and they are missing, we could open a separate ticket to add them.

comment:6 Changed 3 years ago by Tim Graham

Has patch: unset

#17664 "{% if %} template tag silences exceptions inconsistently" and a couple related tickets might be relevant to that.

comment:7 Changed 2 years ago by Alasdair Nicol

Has patch: set

New pull request: https://github.com/django/django/pull/6532

I had a quick look at #17664, but I wasn't sure what I should do for this ticket. If more changes/test cases related to unhandled exceptions are required, I think somebody else will have to take over the ticket.

comment:8 Changed 2 years ago by Tim Graham <timograham@…>

In dac075e:

Refs #26479 -- Documented is/is not if tag operator behavior for nonexistent variables.

comment:9 Changed 2 years ago by Tim Graham

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top