[Django] #28071: ExtendsNode history initialized with context origin rather than own origin

50 views
Skip to first unread message

Django

unread,
Apr 11, 2017, 4:44:17 PM4/11/17
to django-...@googlegroups.com
#28071: ExtendsNode history initialized with context origin rather than own origin
-------------------------------------------+------------------------
Reporter: John D'Ambrosio | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
While the "extends" tag and blocks are typically used to extend a base
template, one can also leverage it to extend an included template with
blocks, as long as the rules of block inheritance are respected. A use
case for this might be a base template that includes a menu stub:

{% include 'menu.html' %}

and then the bottom layer menu.html is something like

{% block menu-items %}
<li>Home</li>
{% endblock %}

and then an installed app higher in the load order makes its own menu.html
as follows:

{% extends 'menu.html' %}
{% block menu-items %}
{{ block.super }}
<li>My App</li>
{% endblock %}

Current test coverage has some similar cases in that they a) make an
included template with blocks and b) override those blocks, but there are
currently no tests that validate that {{ block.super }} works as expected
in that context.

Issue:

The current ExtendsNode behavior initializes the history from the
context's origin instead of the node's origin. This results in it making
two renders of the same origin, which in turn causes anything added
above/below {{block.super}} to render twice.

In the example above, I would end up with:

<li>Home</li>
<li>My App</li>
<li>My App</li>

Proposed Solution:

By changing the initial history entry to be the node's origin, we ensure
the behavior works correctly for both a base template and an included
template.

In the solution provided, a simple test is added to validate the behavior.
Before the change the test would fail because it would render the new
content in the block twice (first time the origin in the history is for
the context's base template, not the calling tag's template's origin),
which results in it adding the node's origin the first pass, and then
rendering it a second time before skipping it. This results in the
string: "12ABB"

After the change, we get the expected result of: "12AB"

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

Django

unread,
Apr 11, 2017, 4:48:15 PM4/11/17
to django-...@googlegroups.com
#28071: ExtendsNode history initialized with context origin rather than own origin
-------------------------------------+-------------------------------------
Reporter: John D'Ambrosio | Owner: John
| D'Ambrosio
Type: Bug | Status: assigned

Component: Template system | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by John D'Ambrosio):

* owner: nobody => John D'Ambrosio
* status: new => assigned


Comment:

https://github.com/django/django/pull/8234

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

Django

unread,
Apr 12, 2017, 8:55:43 AM4/12/17
to django-...@googlegroups.com
#28071: ExtendsNode history initialized with context origin rather than own origin
-------------------------------------+-------------------------------------
Reporter: John D'Ambrosio | Owner: John
| D'Ambrosio
Type: Bug | Status: assigned
Component: Template system | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by John D'Ambrosio):

* has_patch: 0 => 1


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

Django

unread,
Apr 12, 2017, 12:02:54 PM4/12/17
to django-...@googlegroups.com
#28071: ExtendsNode history initialized with context origin rather than own origin
-------------------------------------+-------------------------------------
Reporter: John D'Ambrosio | Owner: John
| D'Ambrosio
Type: Bug | Status: assigned
Component: Template system | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


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

Django

unread,
Apr 24, 2017, 12:42:04 PM4/24/17
to django-...@googlegroups.com
#28071: ExtendsNode history initialized with context origin rather than own origin
-------------------------------------+-------------------------------------
Reporter: John D'Ambrosio | Owner: John
| D'Ambrosio
Type: Bug | Status: assigned
Component: Template system | Version: 1.9

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by John D'Ambrosio):

* version: 1.11 => 1.9


Comment:

Adjusting versions affected--this has been around since recursive template
loading was introduced in 1.9.

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

Django

unread,
May 27, 2017, 5:26:38 PM5/27/17
to django-...@googlegroups.com
#28071: ExtendsNode history initialized with context origin rather than own origin
-------------------------------------+-------------------------------------
Reporter: John D'Ambrosio | Owner: John
| D'Ambrosio
Type: Bug | Status: assigned
Component: Template system | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by John D'Ambrosio):

Updated per feedback from Tim Graham.

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

Django

unread,
Jun 13, 2017, 1:10:27 PM6/13/17
to django-...@googlegroups.com
#28071: ExtendsNode history initialized with context origin rather than own origin
-------------------------------------+-------------------------------------
Reporter: John D'Ambrosio | Owner: John
| D'Ambrosio
Type: Bug | Status: closed

Component: Template system | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"be68c0bf637d9b28780753575b889946a734ca0e" be68c0b]:
{{{
#!CommitTicketReference repository=""
revision="be68c0bf637d9b28780753575b889946a734ca0e"
Fixed #28071 -- Fixed {% extends %} origin history.
}}}

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

Reply all
Reply to author
Forward
0 new messages