Problem/Motivation

In #2438017-49: Entity reference does not validate auto-created entities it has been found out that the recursive validation is broken in the case where a constraint validator is triggering a new validation execution chain involving the same constraint validator, in which case the execution context of the current constraint validator will be exchanged from the triggered validation chain.

The problem relies in an optimization, which is instantiating the constraint validators only once, which in the case of a recursive validation is wrong.

The Drupal optimization is in \Drupal\Core\Validation\ConstraintValidatorFactory::getInstance().

Symfony offers a similar optimization in \Symfony\Component\Validator\ConstraintValidatorFactory::getInstance()

Proposed resolution

Constraint validators, which could trigger a validation execution should not be shared, but always newly instantiated.

Two possible approaches:

  1. Introduce \Symfony\Component\Validator\ConstraintValidatorInterface::isShareable(), which should be implemented by each constraint validator and ones which are triggering validation should return FALSE. While this solution will keep the optimization, it doesn't necessary prevent from mistakes.
  2. Remove the optimization and don't share the constraint validators.

The second option might increase the used memory, when validating a nested entity structure or a lot of entities in a single request, but is more stable and secure than the first one.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

hchonov created an issue. See original summary.

hchonov’s picture

Issue summary: View changes
hchonov’s picture

StatusFileSize
new6.14 KB
new7.33 KB

I've created a kernel test using the entity system as it easier to understand what is happening.

The last submitted patch, 3: 2935405-3-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hchonov’s picture

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

borisson_’s picture

StatusFileSize
new802 bytes
new7.23 KB

Fixed coding standards, this patch looks good and I like the test coverage, but I think someone with more knowledge about the validation system should RTBC this patch.

Status: Needs review » Needs work

The last submitted patch, 7: 2935405.patch, failed testing. View results

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

smustgrave’s picture

So the fix here appears to be around ConstraintValidatorFactory which was already fixed in https://www.drupal.org/project/drupal/issues/3096811 so this can probably be closed as duplicate?

And the blocker tag could then be removed correct?

borisson_’s picture

Status: Needs work » Closed (duplicate)
Issue tags: -blocker

Yes, you're right @smustgrave