Skip to content

Django 4.0 compatibility issue: Node.render should return a string #166

Closed
@thibaudcolas

Description

@thibaudcolas

Issue Summary

cc @nickmoreton who fixed our test data in #165. Our test suite was failing in Django 4.0 because the new version of Django assumes the output of Node.render is a string. The error we got in our test suites was from Django’s templates rendering:

sequence item 4: expected str instance, NoneType found

This was a misc. performance improvement – from the release notes:

NodeList.render() no longer casts the output of render() method for individual nodes to a string. Node.render() should always return a string as documented.

Corresponding PR: django/django#14503, and blame of those three lines.

Steps to Reproduce

Use this library and override a tag by providing raw data, with a value other than a string as the tag output.

Potential fixes

One option would be for us to re-introduce this casting for backwards compatibility. I believe it’s only needed here:

Another option would be to keep our implementation as-is and document the issue so people upgrading to Django 4.0 are aware they’ll need to change their raw definitions to be strings. We’d also want to remove/change the test cases updated in #165, as right now they aren’t testing much. We could also consider adding an assert for this in our code / check the type and throw a custom exception. Not too sure if worthwhile or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdecision neededThis requires a decisiondjangoRelated to Django templates capabilities

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions