Problem/Motivation

You can have default config entities with a wrong filename, which doesn't match what is actually the config entity ID. That can result in strange bugs, just spend too much time debugging a problem I had in a distribution where a test started failing with #2930996: Config installer doesn't install possible installable config.

Proposed resolution

Fail early and clear with an exception in such a situation.

alexpott: @berdir I'm pondering if we can do if ($entity->getConfigDependencyName() !== $name) in the ConfigInstaller.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Berdir created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new1.45 KB

Turns out we have a simpler and less fragile way to test this than (ab)using the getConfigDependencyName() method.

/me wonders what is going to break.

I've triggered a E_USER_WARNING because I think we should produce an error in this situation but I think it should be recoverable (at least in Drupal 8.x).

alexpott’s picture

StatusFileSize
new2.49 KB
new3.94 KB

Here's a test and a fix for the one place found so far in core that had this wrong - it was test code.

The last submitted patch, 2: 2972003-2.patch, failed testing. View results

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Nothing to add, looks good.

  • larowlan committed add2370 on 8.6.x
    Issue #2972003 by alexpott: Verify that the file name matches the ID...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed as add2370 and pushed to 8.6.x.

I think throwing a new warning is something we'd only want to do in a minor, so opting not to backport.

alexpott’s picture

+1 to only adding a new warning to the next minor.

quietone’s picture

Last night commerce_migrate tests started to fail because of this fix. So, I am just wondering if this should have a change record?

quietone’s picture

Status: Fixed » Needs work

Set to NW to get answer to my question

larowlan’s picture

Title: Verify that the file name matches the ID when installing configuration » [Needs change record] Verify that the file name matches the ID when installing configuration

Sure

berdir’s picture

Well, you're welcome to add one because I'm not sure what to write there? IMHO, the error message is clear and you don't need any other information to fix it. Nor will someone see the change record and actively look for misnamed configuration.

There is no reason why you'd do this on purpose, the only reason is typos/renames and now we are just more strict in validating it early, before it might have caused some weird side effects later, e.g. in the referenced issue.

It's also "only" a warning, so just breaks tests and not actual sites yet.

idebr’s picture

Search API also had a failing test: #2973047: Automated test failure after #2972003 Verify that the file name matches the ID when installing configuration
Test result page: https://www.drupal.org/pift-ci-job/965328

Being unaware of this issue, the warning message could probably be more verbose:
The configuration file name "field.storage.entity_test.links" does not match the its specified ID "entity_test_mulrev_changed.links"

Regarding the change record: its content could be fairly straightforward:

Title: ConfigInstaller now checks if a configuration file name matches it specified id.

I agree with Berdir in #12 though, this issue is fairly straight forward to fix with the current error so I had not expected to find a change record.

drunken monkey’s picture

Title: [Needs change record] Verify that the file name matches the ID when installing configuration » Verify that the file name matches the ID when installing configuration
Status: Needs work » Fixed

Regarding the Search API issue, there is actually a weird phenomenon: when you look at #2973047-2: Automated test failure after #2972003 Verify that the file name matches the ID when installing configuration, you'll see the patch invalidly changes the IDs to the complete config keys, to completely match the filename (minus ".yml"). However, it still passes – any explanation for that?
I first thought the change here might just use strpos() or something like that, which might explain it – but with the equality check I see here, I don't really know why it wouldn't detect this error, too?

Regarding change record: A CR would have been nice insofar as I, when I first saw that fail for a patch in an issue, spent a few minutes to find out whether the fail was actually caused by the patch or in HEAD. If I'd seen a CR about this before that, it might have saved me a few minutes of time.
So, here is my take on a change record. If someone else thinks it's OK like this, please publish!
As said, though, I'm not saying a CR is 100% necessary – but if it might save someone a few minutes of time, why not?

idebr’s picture

The change record was published by Berdir, see https://www.drupal.org/node/2974112/revisions

Status: Fixed » Closed (fixed)

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

chi’s picture