Follow-up to #2432791: Skip Config::save schema validation of config data for trusted data

Problem/Motivation

#2432791-83: Skip Config::save schema validation of config data for trusted data has an improvement and has been missed as part of #2432791: Skip Config::save schema validation of config data for trusted data

Proposed resolution

Fix it.

Remaining tasks

  • Review
  • Commit

User interface changes

None

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes Issue category Bug because major performance/DX/UX impact on config import Issue priority Critical because of the massive performance improvements to the installer and cold cache view of node/1

-->

Comments

vijaycs85’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update
alexpott’s picture

Title: Improve ConfigEntityBase class » Use configuration schema in ConfigEntityType::getPropertiesToExport()

Re-titling so the issue is a bit more specific.

See #2432791-105: Skip Config::save schema validation of config data for trusted data - I'm not convinced about this change.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new11.83 KB

Something like this.

tim.plunkett’s picture

Component: configuration system » configuration entity system

Right now in HEAD, if you call toArray() twice in a row, it checks the schema twice. Not true with this patch.

alexpott’s picture

+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php
@@ -165,9 +166,9 @@ protected function checkStorageClass($class) {
-  public function getPropertiesToExport() {
...
+  public function getPropertiesToExport($entity_id) {

Still not convinced about the coupling of ID to the entity type method.

re #4 on the second check it will be cached in schema so it's not a big saving - right? Also it only checks schema if you don't use the annotation.

tim.plunkett’s picture

StatusFileSize
new10.93 KB
new5.63 KB

Duh, we don't need that because config schema is smarter than us.

Because there's no way anyone is sneaky enough to define a per-entity-id schema, right? (please, right!?)

The last submitted patch, 3: use_configuration-2483407-3.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 6: 2483407-6.patch, failed testing.

yched’s picture

Heh, I so much wish accessing the schema didn't require a valid entity ID, alas currently it does.
Because of the schema is at prefix.*.*.* (with an unknown number of *s)

See #1977206: Default serialization of ConfigEntities, where I hit that wall as well (comments #26 to #31).
In short, we know the config prefix for an entity type, but not the number of dynamic parts in its IDs, which is what config schemas are keyed by...

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new21.56 KB
new27.71 KB

Yes, @alexpott and I had a conversation about that. He also mentioned you had an idea about tying the schema to the entity type more closely, which is what I've done here.

alexpott’s picture

I think I like this change - it'd be good to get @yched's thoughts on this because I think this issue has caused him head scratches in the past.

+++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php
@@ -159,6 +159,20 @@ public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE, $is
+  public function getDefinitionForEntityType($entity_type_id) {
+    $id = 'undefined';
+    foreach ($this->getDefinitions() as $definition_id => $definition) {
+      if (isset($definition['config_entity_type']) && $definition['config_entity_type'] === $entity_type_id) {
+        $id = $definition_id;
+        break;
+      }
+    }
+    return $this->getDefinition($id);
+  }

Given the number of definitions it might be worth building up a static map here.

tim.plunkett’s picture

StatusFileSize
new28.66 KB
new27.96 KB
new2.98 KB

Agreed.

yched’s picture

Huge +1 on having a more direct relation between an entity type and its config schema :-D

I would have thought that the simpler way to have that relationship is to put the missing info on the entity type (since it already has the "config_prefix"), rather than pointing back from the schema to the config entity type ID (which then could be inconsistent with what the config entity's "config_prefix" says) ?

It looks like the proposed change means a hard BC break anyway (your config entity stops working if its config schema doesn't have a 'config_entity_type' entry). If we're ready to break APIs for this (which I'm all for), then replacing
'config_prefix' = 'my.prefix'
by
'config_pattern' = 'my.prefix.*.*.*'
in the entity annotation would be more intuitive, faster, and with no risk of inconsistencies ?

The "config_pattern" directly points to the correct schema entry, and you can deduce the config_prefix from it (the part before the first '.*')

The last submitted patch, 6: 2483407-6.patch, failed testing.

tim.plunkett’s picture

The patch as it stands is only a BC break for those NOT using the new config_export annotation. If that exists, this code never runs.
(Of course, that's brand new and I doubt anyone is using it yet)

Changing config_prefix to config_pattern would be a BC break for everyone.

Honestly I am +1 to being able to look at a config schema and see the entity type it's for. If your entity type has some weird prefix, it can be hard to track backwards from the schema to the exact entity type...

yched’s picture

The patch as it stands is only a BC break for those NOT using the new config_export annotation. If that exists, this code never runs.

Well, the new public function getDefinitionForEntityType() breaks if the config schema for your entity type doesn't point back to the entity_type_id. OK, the method is new, but still, the definition of "being a valid config entity for which public methods work" does change, that seems like a BC break to me ?

If your entity type has some weird prefix, it can be hard to track backwards from the schema to the exact entity type...

Yeah, dunno. This is still putitng two separate related informations on both ends of the relationship (config_prefix is on the Entity, entity_type is on the schema, which also implictly includes a config_prefix, which might or might not be the same). Feels like a convoluted denormalized mental model, esp. when one single information in one place would be enough :-)

alexpott’s picture

+++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php
@@ -159,8 +168,26 @@ public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE, $is
+      $this->entityTypeDefinitions[$entity_type_id] = $this->getDefinition($id);

let's just store the definition ID instead so we don't have unnecessary duplication between $this->definitions and $this->entityTypeDefinitions.

tim.plunkett’s picture

StatusFileSize
new28.68 KB
new2.52 KB

#16, I'll take a look at rewriting things in the other direction tomorrow.

#17, sure, okay

The last submitted patch, 12: 2483407-12-PASS.patch, failed testing.

The last submitted patch, 12: 2483407-12-FAIL.patch, failed testing.

alexpott’s picture

+++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php
@@ -169,7 +169,7 @@ public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE, $is
+    if (TRUE || !isset($this->entityTypeDefinitionIds[$entity_type_id])) {

debug?

Status: Needs review » Needs work

The last submitted patch, 18: 2483407-18.patch, failed testing.

The last submitted patch, 10: 2483407-10.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new28.63 KB

Reroll.

Status: Needs review » Needs work

The last submitted patch, 24: 2483407-config-export-24.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new28.57 KB
new892 bytes

Status: Needs review » Needs work

The last submitted patch, 26: 2483407-config-export-26.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

alexpott’s picture

We definitely do fallback to using schema but this happens in ::toArray(). See

    $properties_to_export = $entity_type->getPropertiesToExport();
    if (empty($properties_to_export)) {
      $config_name = $entity_type->getConfigPrefix() . '.' . $this->id();
      $definition = $this->getTypedConfig()->getDefinition($config_name);
      if (!isset($definition['mapping'])) {
        throw new SchemaIncompleteException("Incomplete or missing schema for $config_name");
      }
      $properties_to_export = array_combine(array_keys($definition['mapping']), array_keys($definition['mapping']));
    }

However I suspect this issue is a duplicate of #2666392: Unable to revert third party settings via config import and that that issue will fix this and the problems seen in #2977669: Spec Compliance: some entity types have an "id", "type" or "uuid" field, this violates the spec

gabesullice’s picture

@alexpott, toArray won't work for JSON API because we're iterating over all config entity types and trying to set up field aliases during a router rebuild, meaning that we don't have any individual entities "in hand", we're operating on the type level alone.

#2666392: Unable to revert third party settings via config import actually exacerbated the issue: See: #2986899: Drupal core compatibility: SchemaIncompleteException for some config entity types


UPDATE: I read more into the issue and realized that the schema fallback was moved to getPropertiesToExport, so it does seem like this is now a duplicate.

We still have the same fundamental issue though. We don't have an entity in hand, which would be needed in order to pass a value for the $id argument.

alexpott’s picture

One problem here is that the schema often depends on the data - for example a views schema depends on the display plugins etc. even the top level elements in a config entity can be dynamically determined based on the data.

wim leers’s picture

One problem here is that the schema often depends on the data - for example […]

Darn, indeed! :( However, top-level keys' schema remains the same AFAIK. And those are the "properties to export".

wim leers’s picture

Let's continue this discussion at #2666392-53: Unable to revert third party settings via config import and close this as a duplicate?

alexpott’s picture

Title: Use configuration schema in ConfigEntityType::getPropertiesToExport() » Allow configuration schema fallback in ConfigEntityType::getPropertiesToExport() to work without an ID

Re-titling to scope this issue more tightly to the problem that now needs to be solved.

wim leers’s picture

Okay, so this isn't a duplicate of #2666392: Unable to revert third party settings via config import after all. Thanks for clarifying!

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

Version: 9.4.x-dev » 10.1.x-dev
Priority: Normal » Major
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new146 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

Issue tags: +Configuration schema

I started working on #2300677: JSON:API POST/PATCH support for fully validatable config entities and encountered this. Adding one more tag to improve discoverability.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.