craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

[4.x]: Project-config-created Singles missing from element queries until first save #10939

Closed mattstein closed 2 years ago

mattstein commented 2 years ago

Description

Immediately after installing Craft and applying project config, query behavior for Singles differs between Craft 3 and Craft 4.

This element query returns the homepage entry as expected in Craft 3, but returns null in Craft 4:

Entry::find()->slug('home')->one();

To have the entry returned in Craft 4, you can either...

The initial state of the entry in the control panel—before any content migration or re-save—differs.

Craft 3:

craft-3

Craft 4:

craft-4

Notice how the status is “Enabled” and “Live” in Craft 3 and “Enabled” + “Enabled” in Craft 4. The latter immediately changes to “Live” after you press Save.

Steps to reproduce

  1. Check out https://github.com/craftcms/starter-blog at its main branch, establish an environment for it, and run php craft install. (Project config should automatically be applied.)
  2. Run the included content migration, which should proceed successfully.
  3. In the control panel, go to EntriesSinglesHome and observe that the Site Introduction Redactor field has content in it.
  4. Wipe your database and repeat step 1 with the feature/craft-4 branch.
  5. Edit the included content migration, to remove ->status(null) here.
  6. Run php craft up and notice the content migration fails with the message “Home is missing.”.

Expected behavior

Homepage element query and migration should work identically in Craft 3 and Craft 4 since we’ve got an enabled and presumably live single.

Actual behavior

Element query requires ->status(null) in Craft 4, and the entry itself changes status on save with no edits.

Craft CMS version

4.0.0-beta.4

PHP version

8.0.15

Operating system and version

macOS 12.3.1

Database type and version

MySQL 8.0.26

Image driver and version

Imagick 3.6.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

brandonkelly commented 2 years ago

Fixed for the next release!

brandonkelly commented 2 years ago

Craft 4.0.0-RC1 is out now with this fix.