While writing a PHPUnit functional test that installs a full install profile (Lightning, in this case), I encountered this error:

Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for core.entity_form_display.scheduled_update.multiple_node_embargo.default with the following errors: core.entity_form_display.scheduled_update.multiple_node_embargo.default:content.entity_ids.settings.size variable type is string but applied schema class is Drupal\Core\TypedData\Plugin\DataType\IntegerData

I traced this a bit and discovered that it was due to this error in EntityReferenceAutocompleteWidget:

  public static function defaultSettings() {
    return [
      'match_operator' => 'CONTAINS',
      'size' => '60',
      'placeholder' => '',
    ] + parent::defaultSettings();
  }

Config schema says size should be an integer. The widget is defining it as a string for some reason. That's no good :) As far as I can tell, there is no reason it should be a string, and this will certainly trip up other config-aware tests. So it should be fixed in core.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Here's a patch; not sure if it needs tests. If it does, I'm not sure what kind of tests it needs. A little guidance on that front would be appreciated!

phenaproxima’s picture

Status: Active » Needs review

D'oh!

jibran’s picture

Priority: Minor » Normal
Issue tags: +Needs tests

Nice catch! Let's write some tests.

phenaproxima’s picture

Happy to, but I'm not sure how exactly to go about testing this. Any guidance would be heavily appreciated :)

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

phenaproxima’s picture

Okay, here we go. A bit awkward, to be sure, but EntityReferenceAutocompleteWidget does not seem to have a dedicated unit test :)

jibran’s picture

The test looks good. I think we need to update the existing formatters settings as well so we need an upgrade path and upgrade path tests.

phenaproxima’s picture

Here's a first crack at the update path. No tests yet, though.

amateescu’s picture

The upgrade function looks great to me, just one comment so far:

+++ b/core/modules/system/system.install
@@ -2042,3 +2042,27 @@ function system_update_8403() {
+function system_update_8404() {

Field types, widgets and formatters are still in the "field" realm of the Entity Field API, and we usually put field-related updates in field.install.

So this should be moved there as field_update_8401() ;)

jibran’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/system.install
@@ -2042,3 +2042,27 @@ function system_update_8403() {
+function system_update_8404() {

We are not changing the config schema structure we are just updating existing value so we should use post-update function for this.

+++ b/core/modules/system/system.install
@@ -2042,3 +2042,27 @@ function system_update_8403() {
+  foreach ($config_factory->listAll('core.entity_form_display') as $name) {

Now that schema is correct just load the form display entity using entity api and save it in post-update hook.

phenaproxima’s picture

Status: Needs work » Needs review
Issue tags: -Needs upgrade path tests
FileSize
5.88 KB

Wrote an update path test and addressed @amateescu's feedback in #10, then @jibran's feedback in #11. :)

jibran’s picture

Thanks, @phenaproxima this was quick. :D

  1. +++ b/core/modules/field/field.post_update.php
    @@ -82,3 +82,24 @@ function field_post_update_remove_handler_submit_setting() {
    +        $component['size'] = (int) $component['size'];
    

    If the schema type is correct then why do we need typecasting here?

  2. +++ b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php
    @@ -49,14 +49,22 @@ public function testEntityReferenceAutocompleteWidget() {
    +      ->defaultSettings();
    +    $this->assertInternalType('integer', $settings['size']);
    

    We are only checking the default settings. What about the settings? Is this correct for save settings?

phenaproxima’s picture

Adding a fail patch at @jibran's request.

Status: Needs review » Needs work

The last submitted patch, 14: 2885441-13-FAIL.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Needs review

Fail patch failed? Good, I say.

jibran’s picture

Status: Needs review » Needs work

As confirmed by @phenaproxima in IRC that the issue is only with default size value, not with the saved size value. This means we don't need an upgrade path we only need a test to verify that saved size value is an integer

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.

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.

dwkitchen’s picture

No longer applies on 8.8.x

dwkitchen’s picture

Re-roll to 8.8.x

acbramley’s picture

Removed the upgrade path, update test, and update fixture as per #17

Would be great to get this in as it's blocking #2863188: Hardcoded result size limit in the entity reference autocomplete widget.

Status: Needs review » Needs work

The last submitted patch, 23: 2885441-23.patch, failed testing. View results

hchonov’s picture

+++ b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php
@@ -61,6 +61,14 @@ public function testEntityReferenceAutocompleteWidget() {
+    $plugin_collections = $display_repository->getPluginCollections();
+    $settings = $plugin_collections['widgets']
+      ->get('entity_reference_autocomplete')
+      ->defaultSettings();

This should be:

$settings = $display_repository->getFormDisplay('node', 'page')
->getComponent($field_name)['settings'];
hchonov’s picture

As confirmed by @phenaproxima in IRC that the issue is only with default size value, not with the saved size value. This means we don't need an upgrade path we only need a test to verify that saved size value is an integer

Then it would be better to check the type before and after saving the form display.

hchonov’s picture

Actually I think that it is enough to only load EntityReferenceAutocompleteWidget and all of its subclasses and simply call their defaultSettings() method and asserts, that the size is an integer - of course only if 'size' is present in the returned settings.

Even better - let's do this for all widgets and formatters and check their default values against the specified type in their schema. Having such a general test will show if we have more similar inconsistencies and also will prevent us from introducing new inconsistencies with new code.

acbramley’s picture

Status: Needs work » Needs review
FileSize
1.91 KB
2.36 KB

Went for #26 over #27 as that sounds out of scope of this issue and a good candidate for a follow up.

hchonov’s picture

Status: Needs review » Reviewed & tested by the community

That is fair. I think that it looks good now. Thank you.

larowlan’s picture

  • larowlan committed 49fae2a on 8.8.x
    Issue #2885441 by phenaproxima, acbramley, dwkitchen, jibran, hchonov:...
larowlan’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 49fae2a and pushed to 8.8.x. Thanks!

Needs re-roll for 8.7.x

acbramley’s picture

Status: Patch (to be ported) » Needs review
FileSize
2.24 KB

Re-rolled for 8.7.x

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

  • catch committed be3043f on 8.7.x
    Issue #2885441 by phenaproxima, acbramley, dwkitchen, jibran, hchonov,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed the 8.7.x backport, thanks!

Status: Fixed » Closed (fixed)

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

bogdog400’s picture

I'm still getting this error when running "composer upgrade" because composer tries to just install the patch.

Issue #2885441: EntityReferenceAutocompleteWidget should define its size setting as an integer)
   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2885441-2.patch


  [Exception]
  Cannot apply patch Issue #2885441: EntityReferenceAutocompleteWidget should
   define its size setting as an integer (https://www.drupal.org/files/issues
  /2885441-2.patch)!

dwkitchen’s picture

@bogdog400, you no longer need to apply the patch it has been committed. Remove it from your composer.json file.