Whatever the outcome of the "hardcoded UUIDs in shipped config files" discussion, it will probably require that field.instance.*.yml files stop referencing fields by their uuid. It would make things clearer anyway.

The Entity API cleanups and refactorings that happened since the original "convert Field API to CMI" patch should make that possible now.

Comments

yched’s picture

Assigned: Unassigned » yched

Having a crack at this

yched’s picture

Status: Active » Needs review
StatusFileSize
new15.46 KB

Let's see what breaks.

Status: Needs review » Needs work

The last submitted patch, 2: field_uuid_in_instance_yml-2143519-1.patch, failed testing.

yched’s picture

Status: Needs work » Needs review
StatusFileSize
new15.45 KB
new1.15 KB

The last submitted patch, 4: field_uuid_in_instance_yml-2143519-3.patch, failed testing.

yched’s picture

alexpott’s picture

+++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php
@@ -214,15 +221,17 @@ class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface {
+   *   - field_uuid: (optional) The uuid of the field this is an instance of. If
+   *     specified, this has priority over the 'field_name' property.

So this takes priority why? For deleted fields, right? I think we should say this here. Also do you think it is worth making it so this will ONLY be used for deleted fields?

yched’s picture

StatusFileSize
new15.51 KB
new2.6 KB

Yes, deleted instances have an additional "field_uuid" property, but I don't want to break if the "field_name" property is still there (it is not "wrong" per se, it's just not the one we want to use for determining which field to use).
So the logic is:
- use the field_uuid if present
- else use the field_name, excluding deleted fields

Making this work only on deleted fields: probably a good idea. Lets us get rid of a field_read_fields() call, so attached patch goes with that.

The last submitted patch, 8: field_uuid_in_instance_yml-2143519-8.patch, failed testing.

yched’s picture

StatusFileSize
new15.18 KB
new2.35 KB

Hah, so, you can be a deleted instance of a non-deleted field.
In that case, you have a field_uuid property, but your field is not deleted.

I feel a bit uncomfortable about enforcing that this only gets used by deleted instances actually. I'd rather punt on that for now.

Also, until #1503314: Remove the concept of active / inactive (field types, storage) from Field API gets in (patch should be ready, needs committers feedback on comment #25 ;-)), we still need to account for the case of "inactive, deleted" fields.

So updated patch basically just moves the existing "if field_uuid specified" case on top of the "if entity_type / field_name specified" case, so that it takes precedence.

Status: Needs review » Needs work

The last submitted patch, 11: field_uuid_in_instance_yml-2143519-11.patch, failed testing.

yched’s picture

Status: Needs work » Needs review
StatusFileSize
new16.29 KB

Forgot a chunk in the reroll.

sun’s picture

I'd like to better understand this change proposal.

Could you explain why it is a good idea to replace a hard and unique reference ID with a soft reference ID whose target can be switched out and may not be the originally intended target?

I understand the point being made that UUIDs are "ugly" for humans, but

1) I thought we had concluded and decided that humans rarely need to open/touch the raw config files a year ago already, so human-readable configuration file values aren't a priority?

2) Architecturally, we're talking about dependency management here — the weaker the link, the more error-prone is the application. (?)

2.1) Especially when syncing any kind of data between site instances, as a developer or site builder, I'd prefer to have a 100% guarantee that all (entity) references are pointing to the actually intended targets (and not something else by bad luck or coincidence).

2.2) However, I could see the point of this change proposal when limiting its scope to the case of importing default configuration — because e.g. the "body" field will have a different UUID on every installed site. In turn, as a contrib module developer, I cannot provide a default field instance that references the "body" field, as I only know the field name but not its UUID.

If the purpose of this change proposal is 2.2) then I'd think it would make more sense to store both the field_name and the field_uuid in field instance configurations, use the UUID where available, and only support field_name based configuration imports as a fallback where no UUID is known?

yched’s picture

Status: Needs review » Needs work

@sun:
Yup, the purpose is 2.2. As per #2121751: [META] Making configuration synchronisation work, we're moving away from "hardcoded UUIDs in default config", in favor of #2133325: Create a site UUID on install and only allow config sync between sites with the same UUID, and a prerequisite is that field instances shipped in default config stop referring to their field by its UUID.

Only non-deleted fields and instances are stored in config, and for those an [entity type, bundle, field_name] is unambiguous. Deleted fields and instances, for which we need a field_uuid in the instance, are stored in state, and there we make sure the field_uuid is present. So in regular runtime operations, field_uuid is not needed in config.

Now that you mention it though - hm, I can indeed think of race conditions during config sync where that would be an issue :-/ So yeah, writing back the field_uuid on save might be a good thing...

Working on it.

yched’s picture

Status: Needs work » Needs review
StatusFileSize
new13.3 KB
new9.12 KB

Let's see this.
Interdiff attached, but this is mostly reverts, so looking at the patch probably makes more sense.

swentel’s picture

+++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php
@@ -239,28 +246,30 @@ class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface {
+    // creation / or through import of default config files). ¶

Obsolete space at the end. Looks good to me other than that.

yched’s picture

StatusFileSize
new13.3 KB
new871 bytes

Yup, fixed.

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Nice - sweet DX++ too.

The last submitted patch, 18: field_uuid_in_instance_yml-2143519-18.patch, failed testing.

swentel’s picture

The last submitted patch, 18: field_uuid_in_instance_yml-2143519-18.patch, failed testing.

yched’s picture

The last submitted patch, 18: field_uuid_in_instance_yml-2143519-18.patch, failed testing.

yched’s picture

yched’s picture

Title: Have FieldInstance yml files refer to the Field by field name rather than by field_uuid » Allow FieldInstance yml files to refer to the Field by field name rather than by field_uuid

More accurate title

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

catch’s picture

Status: Fixed » Needs work

Rolled this back - undefined method getFieldName() broke the installer.

swentel’s picture

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new13.29 KB

Indeed, #2143263: Remove "Field" prefix from FieldDefinitionInterface methods was committed first and renamed getFieldName() to getName(). Then this patch got committed, which still used getFieldName(). Hence: kaput.

Simple reroll, with only the getFieldName() line changed.

yched’s picture

Indeed, sorry, should have thought of this one :-/
Thanks for the reroll, @Wim. #30 should be good.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Green, back to RTBC

catch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! Re-committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

yched’s picture

Title: Allow FieldInstance yml files to refer to the Field by field name rather than by field_uuid » [Followup] Allow FieldInstance yml files to refer to the Field by field name rather than by field_uuid
Status: Closed (fixed) » Needs review
StatusFileSize
new1.16 KB

Those field_uuid entries we left in field.instance.*.yml are going to be problematic for default config.

As discussed in #2133325: Create a site UUID on install and only allow config sync between sites with the same UUID, the most common real-life workflow is going to be "I populate my module's config/ folder by picking and copying real yml files from my active config".
So we will find leftover 'uuid' and (in the specific case of field.instance.*.yml) 'field_uuid' entries in the default config/ we import.

The direction over there is that 'uuid' entries will just be silently ignored / overwritten by a fresh UUID by the "import default config" process.

But this doesn't apply to our specific field.instance.* 'field_uuid' here, the config system doesn't know about it and won't clean it up. So if present, it will be taken into account in FieldInstance::__construct() and die with a bang because there's no actual field with that UUID...

Attached patch only considers an incoming 'field_uuid' if there's also a 'uuid' present too - i.e it's a yml file from a real "active config" folder. That would work *if* the "import default config" process actually *removes* the leftover 'uuid' entries it finds in default config before doing the corresponding entity_create().

Status: Needs review » Needs work

The last submitted patch, 35: instance_yml-field_uuid-2143519-35.patch, failed testing.

yched’s picture

Status: Needs work » Needs review
swentel’s picture

alexpott’s picture

Anyway to test this?

yched’s picture

The real-life test case would be to test the import of a field.instance with both 'field_uuid' & 'uuid' leftover entries, since this is what files copied from an active store will look like.

The fix in this patch assumes that leftover 'uuid' entries left in config/ folders will be discarded by the "config import" mechanism before they reach the entity_create() step. Is that the case already ?

If not, one way to test this would be to put in some_test_module/config a field.instance file with a leftover 'field_uuid' but no 'uuid'. Would fail on HEAD and pass with the patch.

But ultimately it would be better to test the real life case.

alexpott’s picture

The config installer does not discard or error on existing UUIDs yet. Perhaps this issue should become the more general fix since it has a good chance of providing a test case?

yched’s picture

@alexpott: you mean changing the config installer to discard incoming uuids here in this issue ? Why not, but we're already a followup of a committed patch here.

(#35 is only a one line change and is tightly related to the 1st patch that went in, so it seemed easier to keep it tied to the earlier discussion)

Your call :-)

sun’s picture

swentel’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.19 KB

Rerolled, tentatively moving to RTBC so Alex will actually see the answers.
I'd vote for commit here too anyway as it's small.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 44: instance_yml-field_uuid-2143519-44.patch, failed testing.

swentel’s picture

Status: Needs work » Reviewed & tested by the community

Urg, imagedisplaytest

catch’s picture

Assigned: yched » alexpott

This would have been better in a new issue, I got very confused reading it. Since Alex was mentioned by name, moving to him to give a chance to look at it.

alexpott’s picture

alexpott’s picture

Title: [Followup] Allow FieldInstance yml files to refer to the Field by field name rather than by field_uuid » Allow FieldInstance yml files to refer to the Field by field name rather than by field_uuid
Status: Reviewed & tested by the community » Fixed

Committed 33ade8c and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.