[Django] #20423: Template renderer does not parse numeric variables

45 views
Skip to first unread message

Django

unread,
May 16, 2013, 4:50:12 PM5/16/13
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+-----------------------------
Reporter: antonio@… | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Keywords: number variable
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------
Currently a Variable is defined, according to the django template
[https://docs.djangoproject.com/en/dev/ref/templates/api/ manual], as :

Variable names consist of any combination of alphanumeric characters and
the underscore ("_").

If a variable is composed of numbers only, it will not get its context
data correctly, coming across as an int. This patch assigns the
appropriate context data to the Variable class when it encounters an
integer.

Here's the current behavior:

from django.template.base import Template
from django.template.base import Context
t = Template("{{ 123 }}")
t.render(Context())

u'123'

t = Template("{{ foo }}")
t.render(Context({"foo":"bar"}))

u'bar'

--
Ticket URL: <https://code.djangoproject.com/ticket/20423>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 16, 2013, 5:07:37 PM5/16/13
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+--------------------------------------

Reporter: antonio@… | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:

Keywords: number variable | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by anonymous):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Definitely not full fix, it does cause regressions elsewhere - namely the
view loading a changelist in the Admin.

--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:1>

Django

unread,
May 16, 2013, 5:13:51 PM5/16/13
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+--------------------------------------

Reporter: antonio@… | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:

Keywords: number variable | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by charettes):

The issue is valid but IMHO the code should be fixed to disallow such uses
of number variables and the documentation fixed accordingly (e.g Variable
name can't start with an integer).

I know this might be backward incompatible but I can't see any valid use
case for this behavior, looks more like a side effect/oversight of the
access by index feature. Am I missing something here?

--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:2>

Django

unread,
May 16, 2013, 5:14:07 PM5/16/13
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+------------------------------------

Reporter: antonio@… | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by charettes):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:3>

Django

unread,
May 19, 2013, 6:44:01 AM5/19/13
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+------------------------------------
Reporter: antonio@… | Owner: iapain
Type: Bug | Status: assigned

Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by iapain):

* owner: nobody => iapain
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:4>

Django

unread,
May 20, 2013, 4:43:38 AM5/20/13
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+------------------------------------
Reporter: antonio@… | Owner: iapain
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by iapain):

I totally agree with charettes that there may not be an use case for this.
Hence, I'd propose to add warning first and then raise an exceptions if
integer or float variable names are used. Does it makes sense?

--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:5>

Django

unread,
May 20, 2013, 10:42:06 AM5/20/13
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+------------------------------------
Reporter: antonio@… | Owner: iapain
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by anonymous):

Makes more sense as a doc ticket, agreed! Thanks for looking!

Antonio

--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:6>

Django

unread,
Sep 23, 2020, 2:32:05 PM9/23/20
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+------------------------------------
Reporter: antonio@… | Owner: (none)

Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by felixxm):

* owner: Deepak => (none)
* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:7>

Django

unread,
Feb 8, 2021, 10:36:12 AM2/8/21
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+-----------------------------------------
Reporter: antonio@… | Owner: Tim McCurrach
Type: Bug | Status: assigned

Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Tim McCurrach):

* owner: (none) => Tim McCurrach


* status: new => assigned


Comment:

I have created a PR to update the docs. Given it will now be documented,
adding in any checks or warnings seems like overkill to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:8>

Django

unread,
Feb 22, 2021, 4:15:01 PM2/22/21
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
---------------------------------+-----------------------------------------
Reporter: antonio@… | Owner: Tim McCurrach
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Jacob Walls):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13990 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:9>

Django

unread,
Feb 22, 2021, 4:58:36 PM2/22/21
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
-------------------------------------+-------------------------------------
Reporter: antonio@… | Owner: Tim
Type: | McCurrach
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master

Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* type: Bug => Cleanup/optimization
* component: Template system => Documentation


--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:10>

Django

unread,
Feb 26, 2021, 2:02:28 AM2/26/21
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
-------------------------------------+-------------------------------------
Reporter: antonio@… | Owner: Tim
Type: | McCurrach
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:11>

Django

unread,
Feb 26, 2021, 3:02:53 PM2/26/21
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
-------------------------------------+-------------------------------------
Reporter: antonio@… | Owner: Tim
Type: | McCurrach
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"7587139d35b630a19fdc55a5f3789475e5ed26c8" 7587139d]:
{{{
#!CommitTicketReference repository=""
revision="7587139d35b630a19fdc55a5f3789475e5ed26c8"
Fixed #20423 -- Doc'd that DTL variable names may not be a number.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:12>

Django

unread,
Feb 26, 2021, 3:03:30 PM2/26/21
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
-------------------------------------+-------------------------------------
Reporter: antonio@… | Owner: Tim
Type: | McCurrach
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"7e6e822162c0b567e81d7b4c3a61e6f1041be49f" 7e6e8221]:
{{{
#!CommitTicketReference repository=""
revision="7e6e822162c0b567e81d7b4c3a61e6f1041be49f"
[3.2.x] Fixed #20423 -- Doc'd that DTL variable names may not be a number.

Backport of 7587139d35b630a19fdc55a5f3789475e5ed26c8 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:13>

Django

unread,
Feb 26, 2021, 3:04:06 PM2/26/21
to django-...@googlegroups.com
#20423: Template renderer does not parse numeric variables
-------------------------------------+-------------------------------------
Reporter: antonio@… | Owner: Tim
Type: | McCurrach
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: number variable | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/20423#comment:14>

Reply all
Reply to author
Forward
0 new messages