[5.x]: "Save as a new draft" drops all nested entries (Matrix content) from the new draft

Open
#20,226 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Start by tracing the “Save as a new draft” flow through elements/duplicate and compare it with Drafts::createDraft() and NestedElementManager::maintainNestedElements(). Reproduce the steps with a Matrix field and check whether the new draft receives nested entries and elements_owners rows; done means those entries are preserved.

Written by the indexing model from the issue text.

Description

bug repo:cms
What happened?
Description

When you use "Save as a new draft" from an explicitly created draft, the new draft keeps the title and other plain fields, but every Matrix field comes up empty. The original draft and the canonical entry aren't affected.

We've reproduced this on three unrelated sites, none of which have custom code that touches drafts, duplication, or nested element ownership:

  • 5.11.5.1
  • 5.11.2 (a draft with 11 Matrix blocks produced a new draft with 0)
  • 5.10.4.1

The new draft gets no elements_owners rows. It looks like NestedElementManager::maintainNestedElements() skips nested elements for drafts and expects Drafts::createDraft() to copy them, but "Save as a new draft" goes through elements/duplicate instead, so nothing copies them.

On an entry with a Neo field (Neo 5.5.13), the same action returns a 500 instead: "The source element must be canonical."

Steps to reproduce
  1. Open a published entry that has a Matrix field with a few nested entries.
  2. Create a draft of it, then save the draft.
  3. From that draft, choose "Save as a new draft" from the save menu.
  4. Look at the Matrix field on the new draft.
Expected behavior

The new draft contains the same nested entries as the draft it was created from.

Actual behavior

The new draft's Matrix field is empty. The title and non-nested fields carry over.

Craft CMS version

5.11.5.1 (also reproduced on 5.11.2 and 5.10.4.1)

PHP version

8.4.10

Operating system and version

Linux (DDEV)

Database type and version

MySQL 8.0.40

Image driver and version

Imagick 3.8.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

These are from the 5.11.5.1 site, which is the one the environment details above describe.

  • Amazon S3 2.3.2
  • Amazon SES 3.1.0
  • CKEditor 4.11.4
  • Feed Me 6.11.0
  • Google Maps 5.2.3
  • Icon Picker 3.1.6
  • Imager X 5.2.1
  • Imager X AWS Serverless Transformer 3.0.2
  • JWT Authorization 5.0.1
  • Password Policy 5.1.3
  • RESTful API 5.0.0
  • Retour 5.0.14
  • Scout 6.0.0
  • SEOmatic 5.1.22
  • Sprig 3.7.3
  • Table Maker 5.0.7
  • Typogrify 5.0.3
  • Video Picker 2.1.6
  • Vite 5.0.2
Dominant language
PHP
Stars
3.6k
Forks
712
Avg merge
13h 5m
Merged PRs (30d)
328

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from craftcms/cms

All issues in craftcms/cms

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.