torchbox / torchbox/django-pattern-library

Issue with nested templates and child templates with overridden tags that include another template

Open
#209 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
423
Forks
53
PR merge metrics
No merged PRs in 30d

Description

Found a bug? Please fill out the sections below. 👍

Issue Summary

This issue is present in both 0.7.0 and 1.0.0 versions, but not in 0.6.0

You can repeat the issue by creating a simple template called test_block.html that includes another template in a for loop using include_block

test_block.html:

{% load wagtailcore_tags %}

{% for button in value %}
    {% include_block button %}
{% endfor %}

test_block.yaml:

context:
  value:
    - button
    - button

tags:
  include_block:
    'button':
      template_name: 'patterns/molecules/streamfield/blocks/cta_button_block.html'

test_block.html will render by itself in the pattern library without any issue. However, if we have a stream_block.html template that is being used to include some example blocks for a page.body then we see the bug.

Take a page template that includes the following markup:

{% include_block page.body %}

This will repeatedly use a stream_block template to render the blocks in page.body. The yaml for the stream_block instructs the pattern library to render another template story_container.html, which is only used by the pattern library, and includes a list of example blocks to be rendered for page templates. If we add our test_block.html to this like so it renders an error:

story_container.html:

{% include "patterns/molecules/streamfield/blocks/paragraph_block.html" %}
{% include "patterns/molecules/streamfield/blocks/image_block.html" %}
{% include "patterns/molecules/streamfield/blocks/quote_block.html" %}
{% include "patterns/molecules/streamfield/blocks/cta_button_block.html" %}
{% include "patterns/molecules/streamfield/blocks/document_block.html" %}
{% include "patterns/molecules/streamfield/blocks/test_block.html" %}

The error is as follows:

TypeError at /pattern-library/render-pattern/patterns/pages/standardpages/information_page.html
sequence item 1: expected str instance, NoneType found
Request Method:	GET
Request URL:	http://localhost:8000/pattern-library/render-pattern/patterns/pages/standardpages/information_page.html
Django Version:	3.2.16
Exception Type:	TypeError
Exception Value:	
sequence item 1: expected str instance, NoneType found
Exception Location:	/venv/lib/python3.8/site-packages/django/template/defaulttags.py, line 221, in render
Python Executable:	/venv/bin/python
Python Version:	3.8.16
Python Path:	
['/app',
 '/app',
 '/usr/local/lib/python38.zip',
 '/usr/local/lib/python3.8',
 '/usr/local/lib/python3.8/lib-dynload',
 '/venv/lib/python3.8/site-packages']
Server time:	Fri, 09 Dec 2022 11:14:38 +0000

If I change the include_block tag in test_block.html to a simple include tag and pass it the template name, then the issue no longer occurs. If I change the pattern library version for my project to 0.6.0 the issue no longer occurs.

Steps to Reproduce

Create a build using pattern library version 0.7.0 or higher
Create a test template as described above, with a forloop and an include_block
Try adding the test template to a story_container type template, being used to render a set of example blocks for page.body in the pattern library.

Technical details
  • Python version: 3.8.16.
  • Django version: 3.2.16.
  • Browser version: Chrome Version 107.0.5304.121 (Official Build) (x86_64).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure through the pattern-library render-pattern entry point using test_block.html, stream_block.html, story_container.html, and the nested include_block examples described in the issue. Start by comparing the failing nested-template path with the simple include case; done means the page renders nested overridden tags without the reported TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.