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

Copying a page: exclude_fields_in_copy breaks with DeferringRelatedManager error when a field is a related field #11715

Open
pcraciunoiu opened this issue Mar 1, 2024 · 0 comments · May be fixed by #11809
Labels
status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug

Comments

@pcraciunoiu
Copy link

pcraciunoiu commented Mar 1, 2024

Issue Summary

If you are trying to exclude related fields from being copied, the revision content ends up with a value of DeferringRelatedManager and throws an error on revision.save():

Object of type DeferringRelatedManager is not JSON serializable

Steps to Reproduce

  1. Set up a model, say, blog and a related model author, so you have blog.authors.all()
  2. Set BlogPage.exclude_fields_in_copy = ["authors"].
  3. Try and copy a blog instance from Wagtail admin
  4. 💥
  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes

Technical details

  • Python version: 3.11
  • Django version: 5.0.2
  • Wagtail version: 6.0.1

Working on this

I think the approach would be to properly exclude the field from the revision. Not sure why it's getting the value from page_copy -

https://github.com/wagtail/wagtail/blob/main/wagtail/actions/copy_page.py#L224-L230

This code here causes it to be set to a related manager value.

                    if exclude_field in revision_content and hasattr(
                        page_copy, exclude_field
                    ):
                        revision_content[exclude_field] = getattr(
                            page_copy, exclude_field, None
                        )
@pcraciunoiu pcraciunoiu added status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug labels Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant