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

fix: Ensure that Box content is rendered after update #2638

Merged
merged 1 commit into from
Oct 7, 2024
Merged

Conversation

ewdurbin
Copy link
Member

@ewdurbin ewdurbin commented Oct 7, 2024

This resolves the underlying problem from #2631.

When updated via Django's update_or_create, the new content for a Box is not rendered by django-markupfield's pre_save method unless save() is called.

This is due to the fact that update bypasses calls to save, pre_save, and post_save, from the docs:

Finally, realize that update() does an update at the SQL level and, thus, does not call any save() methods on your models, nor does it emit the pre_save or post_save signals (which are a consequence of calling Model.save())

This resolves the underlying problem from #2631.

When updated via Django's [`update_or_create`](https://docs.djangoproject.com/en/4.2/ref/models/querysets/#update-or-create), the new `content` for a `Box` is not rendered by django-markupfield's [`pre_save`](https://github.com/jamesturk/django-markupfield/blob/2.0.1/markupfield/fields.py#L163-L179) method unless `save()` is called.

This is due to the fact that [`update`](https://docs.djangoproject.com/en/4.2/ref/models/querysets/#django.db.models.query.QuerySet.update) bypasses calls to `save`, `pre_save`, and `post_save`, from the docs:

> Finally, realize that update() does an update at the SQL level and, thus, does not call any save() methods on your models, nor does it emit the pre_save or post_save signals (which are a consequence of calling Model.save())
@ewdurbin
Copy link
Member Author

ewdurbin commented Oct 7, 2024

Summary here is that since the /boxes view and templatetag sensibly use Box.content.rendered and not Box.content, the pre_save method is critical to ensuring that the value passed to content is actually... well... rendered.

@JacobCoffee JacobCoffee changed the title Ensure that Box content is rendered after update fix: Ensure that Box content is rendered after update Oct 7, 2024
@JacobCoffee JacobCoffee merged commit 64b737e into main Oct 7, 2024
6 checks passed
@JacobCoffee JacobCoffee deleted the boxes_save branch October 7, 2024 19:24
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 this pull request may close these issues.

2 participants