Skip to content

fix(plugin-nested-docs): fix bug in logic to determine if doc is a draft #12412

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

crcorbett
Copy link

The current approach fails to handle documents in collections that don't have versioning enabled. In these situations, doc._status is undefined, which causes the current logic to return draft=true and no children are resaved.

Issue: #12411

The current approach fails to handle documents in collections that don't have versioning enabled. In these situations, `doc._status` is undefined, which causes the current logic to return `draft=true` and no children are resaved.
@crcorbett crcorbett changed the title fix(plugin-nested-docs): Fix bug in logic to determine if doc is a draft fix(plugin-nested-docs): fix bug in logic to determine if doc is a draft May 15, 2025
DanRibbens
DanRibbens previously approved these changes May 15, 2025
@@ -115,7 +115,7 @@ export const resaveChildren =
await resave({
collection,
doc,
draft: doc._status === 'published' ? false : true,
draft: (!doc._status || doc._status === 'published') ? false : true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would typically check the collection config to see if versions.drafts is enabled. That said, I see how this would work also.
Good job!

@DanRibbens DanRibbens enabled auto-merge (squash) May 15, 2025 02:38
auto-merge was automatically disabled May 16, 2025 06:47

Head branch was pushed to by a user without write access

@crcorbett
Copy link
Author

Thanks @DanRibbens! I wasn't entirely sure if I was missing the bigger picture with this plugin, so pushed out a quick fix to begin the discussion. Glad to see I was on the right track.

I've updated the PR to include your helpful suggestion regarding checking whether versioning is enabled on the collection, and added a note into the plugin docs regarding descendants not being updated when the parent is in a draft state. Hoping the note helps others find the issue faster in the future.

Feel free to take or leave any of the changes — though I'm glad to finally contribute to Payload!

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