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.
- šŗšøUnited States caesius
Addressing issues that came up in tests.
- Status changed to Needs review
almost 2 years ago 12:54am 4 March 2023 - Status changed to Needs work
almost 2 years ago 2:42pm 4 March 2023 The Needs Review Queue Bot ā tested this issue. It no longer applies to Drupal core. 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.
- Status changed to Needs review
almost 2 years ago 6:21pm 4 March 2023 - šŗšøUnited States caesius
I'm not sure how to get the bot to not test the 9.5.x patch against 10.1.x, so not gonna fight with it.
If someone tries to review this and finds that any of the patches really do not apply, then poke me.
- @caesius opened merge request.
- šŗšøUnited States caesius
I've converted the 10.1.x patch to an MR. Hopefully the NR bot checks that instead of the 9.5 and 10.0 patch files.
- Status changed to RTBC
over 1 year ago 8:55pm 12 May 2023 - šŗšøUnited States smustgrave
Verified the issue by using the snippet in the issue summary.
Added it to the node.module for testing
Used the Article content type from the standard install
Added a simple test filed, set to unlimited
Created an Article and added Test to both fields
Saved fineApplied patch
Edited node
Tried saving again
Validation error was thrown, as expected. - last update
over 1 year ago 29,392 pass - Open on Drupal.org āEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass 39:58 36:12 Running- last update
over 1 year ago 29,391 pass, 2 fail - last update
over 1 year ago 29,391 pass, 2 fail - Open on Drupal.org āEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass - last update
over 1 year ago 29,399 pass - last update
over 1 year ago 29,403 pass - last update
over 1 year ago 29,403 pass - last update
over 1 year ago 29,404 pass - last update
over 1 year ago 29,413 pass - last update
over 1 year ago 29,413 pass - last update
over 1 year ago 29,419 pass - last update
over 1 year ago 29,424 pass - last update
over 1 year ago 29,424 pass - last update
over 1 year ago 29,429 pass - Status changed to Needs work
over 1 year ago 11:46pm 12 June 2023 - š¦šŗAustralia larowlan š¦šŗš.au GMT+10
Looking good, left some comments on the MR, thanks!
- last update
over 1 year ago 29,440 pass - last update
over 1 year ago 29,440 pass - last update
over 1 year ago 29,440 pass - last update
over 1 year ago 29,445 pass - last update
over 1 year ago 29,445 pass - last update
over 1 year ago 29,445 pass - last update
over 1 year ago 29,445 pass - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,445 pass - Status changed to Needs review
over 1 year ago 1:17am 28 June 2023 - šŗšøUnited States caesius
I addressed all MR threads to the best of my ability.
- last update
over 1 year ago 29,446 pass - Status changed to RTBC
over 1 year ago 12:35pm 29 June 2023 - šŗšøUnited States smustgrave
Appears all of @larowlans threads have been resolved.
- last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago Custom Commands Failed - Status changed to Needs review
over 1 year ago 6:16pm 30 June 2023 - šŗšøUnited States caesius
Hate to send my own work back to needs review, but I mulled over one of larowlans suggestions and decided to properly implement it to reduce redundant looping during the "own duplicate value" check.
- last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago Composer error. Unable to continue. - last update
over 1 year ago 29,447 pass - Status changed to RTBC
over 1 year ago 12:08am 3 July 2023 - šŗšøUnited States smustgrave
Update looks good to me. Lets move to committers queue.
- last update
over 1 year ago 29,447 pass - Status changed to Needs work
over 1 year ago 7:00am 3 July 2023 - š¦šŗAustralia larowlan š¦šŗš.au GMT+10
Looking good, left some comments on the MR about coding standards (minor) and one curly one about the update path here for sites with invalid data.
I'll ask the release managers what their thoughts are with respect to that.
- š¦šŗAustralia larowlan š¦šŗš.au GMT+10
I've asked release managers which of these options is the best
a) Do nothing, users will need to fix invalid duplicates next time they save content
b) Some sort of report for users - this will have performance issues - to generate it we'd probably need a background process
c) Some sort of update hook - this could cause data loss issues so feels riskyDiscussed with @lauriii and he agreed a) felt best, but we'd also need a change record and release note snippet (as we'd want to highlight this in release notes).
Tagging as such
I'll wait for a release manager to confirm a) is the best approach and report back either way
- last update
over 1 year ago 29,447 pass - šŗšøUnited States caesius
Updated the MR for coding standards.
My personal opinion regarding this change and its implications for site content editors is that the original functionality for this constraint was not intended to work with multi-valued fields. The only way for this constraint to apply to multi-valued fields would be for a developer to write a module that adds the constraint to the field. I don't believe this constraint is used in core in any way on multi-valued fields, and I can't imagine someone hacking the core user email field to be multi-valued and then using this constraint -- but if they have, they've probably already found it to be broken and applied one of the above patches.
Describing the issue in the change record and noting the situations in which content editing would be adversely affected necessarily requires pointing out that this constraint is being used in a way it wasn't intended, resulting in either not achieving the desired result in the first place or supporting a very specific use case. For the latter, we should instruct developers to write and implement their own constraint that mimics the old functionality.
- Status changed to Needs review
over 1 year ago 8:02pm 3 July 2023 - š¦šŗAustralia larowlan š¦šŗš.au GMT+10
I discussed with @catch who also agreed that a) is the best approach
I added a draft change record and release note snippet
This is ready for review again
- šŗšøUnited States caesius
Change record also needs to mention that the validator will now also work with additional field types, such as Entity Reference fields.
This sentence is also not 100% accurate:
Prior to 10.2.0 the validator only supported single-value fields and would not detect duplicates for fields with more than one value.
It would actually check for duplicates, but only in the first entry (delta) for each field. If someone really wanted to enter duplicate values they could "work around" the constraint by simply making sure the first value is different. It's feasible this unsupported behavior could have been used to hack together functionality where the first value in a field would be a "key." So the CR should mention that if the original behavior was deliberately used in this way then a dev would need to write a new constraint themselves.
This is how I think it should read:
The UniqueFieldValueValidator provides a constraint that can be added to a field to ensure that all values in the field are unique to that entity.
Drupal core uses this constraint for the User's name and mail fields.
Prior to 10.2.0 the validator only supported single-value fields and would not detect all duplicates for fields with more than one value. The first entry in the field would be validated against the first entry in all other entities, but subsequent entries would not be validated for uniqueness, whether against other entities or within the entity itself. Additionally, only simple field types such as plaintext fields would be validated, while entity reference and composite fields would not.
From 10.2.0 the validator will mark entities with duplicates in multi-value fields as invalid, regardless of whether the duplicates occur in other entities or within the validating entity. Additionally, the field's main property will be used for validation, thus providing validation for e.g. Link fields whose main property is the Link URL.
Future edits of content implementing UniqueFieldValueValidator will require removing duplicate values.
If the original behavior of the validator was used deliberately, e.g. for designating only the first value in a multivalue field as a "key," then the constraint will need to be removed from the field and a new custom constraint implemented. See Defining Constraints ā for more information.
- š¦šŗAustralia larowlan š¦šŗš.au GMT+10
@caesius thanks - can you make those edits?
- Status changed to RTBC
over 1 year ago 4:13pm 5 July 2023 - last update
over 1 year ago 29,443 pass - last update
over 1 year ago 29,443 pass - last update
over 1 year ago 29,443 pass - last update
over 1 year ago 29,448 pass - last update
over 1 year ago 29,448 pass - last update
over 1 year ago 29,450 pass - last update
over 1 year ago 29,450 pass - last update
over 1 year ago 29,450 pass - š¦šŗAustralia larowlan š¦šŗš.au GMT+10
Hiding patches as there's an MR
Updating credits
-
larowlan ā
committed 3981c8aa on 11.x
Issue #2478663 by caesius, sanja_m, slashrsm, alphawebgroup, Drews_man,...
-
larowlan ā
committed 3981c8aa on 11.x
- Status changed to Fixed
over 1 year ago 7:17am 20 July 2023 - š¦šŗAustralia larowlan š¦šŗš.au GMT+10
Fixed on commit too, ran the tests locally
--- a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldValueValidator.php +++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldValueValidator.php @@ -14,31 +14,15 @@ */ class UniqueFieldValueValidator extends ConstraintValidator implements ContainerInjectionInterface { - /** - * The entity field manager. - * - * @var \Drupal\Core\Entity\EntityFieldManagerInterface - */ - protected $entityFieldManager; - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - /** * Creates a UniqueFieldValueValidator object. * - * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager + * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager * The entity type manager. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * The entity type manager. */ - public function __construct(EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager) { - $this->entityFieldManager = $entity_field_manager; - $this->entityTypeManager = $entity_type_manager; + public function __construct(protected EntityFieldManagerInterface $entityFieldManager, protected EntityTypeManagerInterface $entityTypeManager) { } /**
Tests output
phpunit -c app/core app/core/tests/Drupal/KernelTests/Core/Validation/UniqueValuesConstraintValidatorTest.php ā³ļø Bootstrapped tests in 0 seconds. š PHP Version 8.1.16. š§ Drupal Version 11.0-dev. šļø Database engine mysql. PHPUnit 9.6.10 by Sebastian Bergmann and contributors. Testing Drupal\KernelTests\Core\Validation\UniqueValuesConstraintValidatorTest .... 4 / 4 (100%) Time: 00:03.177, Memory: 10.00 MB OK (4 tests, 74 assertions)
- šŗšøUnited States caesius
I believe this fully addresses all related/referenced issues as well (some of which are functionally duplicates of each other)
I think the only thing left to do may be to write additional tests to more explicitly test e.g. Link fields and fields with custom properties. #3291483 looks like the best fit for that if we feel more tests are needed to prevent regressions.
Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
over 1 year ago 11:10pm 13 September 2023 - šŗšøUnited States alexdmccabe Orlando, FL, US / Seminole lands
smustgrave ā credited alexdmccabe ā .
- š¦šŗAustralia darvanen Sydney, Australia
smustgrave ā credited darvanen ā .
- š®š³India Hardik_Patel_12 India
smustgrave ā credited Hardik_Patel_12 ā .
- š³šæNew Zealand RoSk0 Wellington
smustgrave ā credited RoSk0 ā .
- š®š³India swatichouhan012
smustgrave ā credited swatichouhan012 ā .
- šŗšøUnited States smustgrave
Moving over credit from š Unique field constraint does not work with any field main property name that is not "value" Closed: duplicate
I think this might have caused another (very similar) regression: https://www.drupal.org/project/drupal/issues/3456964 š Unhandled exception when trying to register a duplicate username with equality mismatch between php and database layer Active