Closed evanbrumley closed 4 years ago
Yeah, I think we'll need to do a point release then. I can try to look at this in the next few days, but if you're able to put up a PR I'd appreciate it!
@evanbrumley I think that #24 will fix this, but I wasn't able to create a reduced test-case. Re-using a context for me caused no issues.
Do you have a reduced test-case for this?
At the very least it would be nice to know if that branch fixes the issue. 😄
@clokep Have just created PR #25, which contains a fix and a test that should demonstrate the issue. Note that an additional step was required after the copy, because Django explicitly tries to preserve the rendering context between copies.
Thanks! I'll take a look at this soon. Oddly the docs don't give any warning about not re-using these. 😕
I just pushed 0.8.1 which includes the fix. Thanks so much! 👍
No problems! Thank you for taking the time to maintain such a useful library :-)
As of 0.8,
django_render_block(...)
was modified to preserve the original context object if it had the typedjango.template.Context
. Unfortunately, context objects are mutable and this has resulted in odd behaviour if django_render_block is called multiple times with the same context object. In our case, we started seeing TemplateNotFound errors because Django's templating engine skipped templates it thought it had already parsed.This is a somewhat urgent issue, because django-templated-email has an unpinned dependency on django-render-block and calls django_render_block multiple times with the same context: https://github.com/vintasoftware/django-templated-email/blob/cba05a7b0f355acdc18174acd1ae468ad77e023d/templated_email/backends/vanilla_django.py#L106
The solution should be as simple as making a deep copy of the context object instead of using it directly.