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

Already rendered Email is re-rendered without context #421

Closed
productaize opened this issue Oct 18, 2022 · 2 comments · Fixed by #425
Closed

Already rendered Email is re-rendered without context #421

productaize opened this issue Oct 18, 2022 · 2 comments · Fixed by #425

Comments

@productaize
Copy link

productaize commented Oct 18, 2022

In closing #403 a change was made to save the template independent of the render_on_delivery flag. This now causes the email to be re-rendered, however without the context. The result is the empty template message (placeholders are replaced with blank).

Either this should be changed to only re-render if Email.message or Email.html_message is empty, or the context should always be stored, as hinted here on 24 Aug

django-post_office/post_office/models.py

@zagl
Copy link
Contributor

zagl commented Oct 18, 2022

If the context is also just stored and nothing else changed it would be render_on_delivery=True by default.

If the context also "can be usefull for admin purposes" it should be saved and Email.message and Email.html_message should be checked for beeing empty.

If the context should not be saved the line

if self.template is not None:

could simply be replaced by
if self.context is not None:

I created a pull request for the latter.

@gabn88
Copy link
Contributor

gabn88 commented Jun 14, 2023

This commit creates a problem with emails that have a context, but no template. I get "AttributeError: 'NoneType' object has no attribute 'subject'".

subject = engine.from_string(self.template.subject).render(self.context)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants