Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thibaudcolas opened this issue Dec 21, 2021 · 2 comments · Fixed by #188
Closed

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

thibaudcolas opened this issue Dec 21, 2021 · 2 comments · Fixed by #188
Labels
bug Something isn't working decision needed This requires a decision django Related to Django templates capabilities
Milestone

Comments

@thibaudcolas
Copy link
Member

thibaudcolas commented Dec 21, 2021

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.

@thibaudcolas thibaudcolas added bug Something isn't working decision needed This requires a decision django Related to Django templates capabilities labels Dec 21, 2021
@thibaudcolas
Copy link
Member Author

@zerolab @bcdickinson when you have a chance I could use your input on this. Would be great for us to agree on a fix before lots of our projects start upgrading to Django 4.0.

@thibaudcolas thibaudcolas changed the title Django 4.0 compatibility issue: expects Node.render to be a string Django 4.0 compatibility issue: Node.render should return a string Dec 21, 2021
@zerolab
Copy link
Member

zerolab commented Dec 22, 2021

My gut feeling is that we should handle this ourselves since we're kind of acting (in a veeery loose sense of the concept) like a fancy NodeList with individual bits patched.

Also, will save updating hundreds of yaml files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working decision needed This requires a decision django Related to Django templates capabilities
Projects
No open projects
3 participants