dev: "This value should not be null" for optional fields

Created on 25 February 2022, almost 3 years ago
Updated 26 May 2023, over 1 year ago

Problem/Motivation

I want to use Conflict along with the Scheduler module .

But, when there's a conflict, the dev version of Conflict marks optional fields as required, when they are not.

This problem does not occur with the alpha version of Conflict.

Steps to reproduce

# 1. Start with vanilla Drupal install (9.3.6 in my case)

# 2. Install dev version of Conflict
composer require 'drupal/conflict:2.x-dev@dev'

# 3. Install Scheduler
composer require 'drupal/scheduler:^1.4'

# 4. Enable
drush en conflict scheduler

5. At /admin/structure/types/manage/article enable Scheduler for publishing and unpublishing this content type

6. Create an article and save

7. Edit the article, open in two tabs (with same user is fine)

8. First tab: change title and save -> saved

9. Second tab: change title and save

Expected result:

Conflict module shows dialog, can resolve as usual

Actual result:

Shows "This value should not be null." and the publish/unpublish fields are shown as required, even though they're not really required

Note

Cannot reproduce with the last Conflict 8.x-2.0-alpha2 release: composer require 'drupal/conflict:^2.0@alpha'

https://git.drupalcode.org/project/conflict/-/commits/8.x-2.x

There's only been one commit between 8.x-2.0-alpha2 and dev:

🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇫🇮Finland hugovk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Assigned to sagar25
  • 🇩🇪Germany jocowood Kamp-Lintfort

    I have debugged this problem together with a colleague, as we also want to use conflict together with scheduler.

    We are pretty sure that this added line of code causes the problem:
    https://git.drupalcode.org/project/conflict/-/commit/d1958eca3852ef55c87...

    The key/value pair conflictWidget will be added to the value array of all fields. Later on the validation of the entity is triggered. Because of the additional information in the value (here data) array, the array is not empty and is considered complex (see [1]). For this reason the array entries are validated individually. Because the datetime information is still null, the NotNullValidator reports a validation.

    Another negative side effect is, that the comparison of the local node and the server node in the conflict module always leads to the result "has changes". FieldComparatorDefault is the only available comparator, which does a simple equals comparison. This comparison is always false, because there is this additional entry conflictWidget.

    Proposed solution:

    A) Place the conflictWidget information at a different location

    B) Add a tidy up function, which is called, when conflict finished its job. We did a quick and dirty try at the end of \Drupal\conflict\Entity\ContentEntityConflictHandler::entityFormEntityBuilder, which seem to fix the bug.

    foreach (array_keys($form_display->getComponents()) as $field_name) {
      if ($entity->getFieldDefinition($field_name)) {
        unset($entity->get($field_name)->conflictWidget);
      }
    }

    We are working on a patch, which we will provide soon.

    [1] \Drupal\Core\TypedData\Validation\RecursiveContextualValidator::validateNode L.163

  • 🇩🇪Germany jocowood Kamp-Lintfort

    It turned out that the quick and dirty solution is also a good and clean solution. Here is a patch for conflict:2.0-alpha3

  • 🇧🇷Brazil webfordreams

    I confirm the patch in comment #6 works for us.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 8
    last update over 1 year ago
    1 pass
  • Issue was unassigned.
  • Status changed to RTBC over 1 year ago
  • 🇩🇪Germany harkonn

    The patch works. Thank you.

Production build 0.71.5 2024