(I did not find this issue reported yet when searching. I apologize if this is a double report.)

I have created a module that defines a custom content entity type. The module code only defines a Title field and hidden fields.

Via the Drupal interface, I added a field named "Category" to this entity type. The Category field is a text list field that only accepts 1 choice ("select" widget).

In /admin/structure/views/, I attempt to create a new Page view to only retrieve instances of this entity that have a certain Category value.

Because one of the Category choices selected for this view contains a period ".", Drupal crashes and displays the following in an otherwise blank page:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Config\ConfigValueException: Dr. BPP key contains a dot which is not supported. in Drupal\Core\Config\ConfigBase->validateKeys() (line 211 of core\lib\Drupal\Core\Config\ConfigBase.php).
Drupal\Core\Config\ConfigBase->validateKeys(Array) (Line: 214)
Drupal\Core\Config\ConfigBase->validateKeys(Array) (Line: 214)
Drupal\Core\Config\ConfigBase->validateKeys(Array) (Line: 214)
Drupal\Core\Config\ConfigBase->validateKeys(Array) (Line: 214)
Drupal\Core\Config\ConfigBase->validateKeys(Array) (Line: 214)
Drupal\Core\Config\ConfigBase->validateKeys(Array) (Line: 161)
Drupal\Core\Config\ConfigBase->setData(Array) (Line: 107)
Drupal\Core\Config\Config->setData(Array) (Line: 279)
Drupal\Core\Config\Entity\ConfigEntityStorage->doSave('protein', Object) (Line: 392)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 259)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 358)
Drupal\Core\Entity\Entity->save() (Line: 637)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 986)
Drupal\views_ui\ViewUI->save() (Line: 312)
Drupal\views_ui\ViewEditForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 583)
Drupal\Core\Form\FormBuilder->processForm('view_edit_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'edit', Array) (Line: 226)
Drupal\views_ui\Controller\ViewsUIController->edit(Object, NULL)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 628)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Problem

We build an array of the selected items when using the InOperator where both the array keys and values are set to the selected item name. If the array key contains a period, this will cause an error when exporting this to config since sequences don't support periods in their keys

Proposed solution

Don't use an array with both keys and values set to the selected items, use a numeric array that only has the values set to the selected items

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jmadden27 created an issue. See original summary.

dawehner’s picture

Component: entity system » views.module

Great bug report!.

That is certainly a bug in views ... the problem is that we store things with key: value in YAML, but we use the "." to specify the hierarchy of elements. One possible solution could be to store the entries using a list rather than an a key value thing (called sequence). Another possibility would be to rewrite those values, like replacing "." with "__" or so.

joachim’s picture

Can the report be simplified? It sounds like this could be reproduced with just an options field on nodes, where one option is '.' -- and dispense with the custom entity part.

jmadden27’s picture

I'm afraid if I simplify it to document something I didn't actually do, I'll get something wrong. I'm very new to Drupal development and just outlined exactly what I did.

joachim’s picture

Title: View creation for custom content entities is broken when filtering by a list field where a filter criterion contains a period » Cannot save a view where a filter value contains a period
Version: 8.1.7 » 8.2.x-dev

Confirming that this is reproducible with just nodes:

- create a text options field on a node type
- add an option consisting of just a period, '.'
- create a view of nodes
- add a filter on the field, and select the period as the filter value
- save the view

BOOM:

> Drupal\Core\Config\ConfigValueException: . key contains a dot which is not supported. in Drupal\Core\Config\ConfigBase->validateKeys() (line 211 of core/lib/Drupal/Core/Config/ConfigBase.php).

jmadden27’s picture

Thanks Joachim! (Not sure how to reply directly to a comment.)

pguillard’s picture

The Config system planned throws exceptions each times it finds a dot in a key - Normal

if (strpos($key, '.') !== FALSE) {
  throw new ConfigValueException("$key key contains a dot which is not supported.");
}

I guess we sloud escape the dot at the time the filter is saved.

joachim’s picture

Title: Cannot save a view where a filter value contains a period » Cannot save a view where a filter value option contains a period

Further clarification: a filter value for a text filter, such as node title, is fine. That's because the period is stored as a value, not an array key.

The problem is specifically when the filter has you choose from options, and the problem is caused by the way that the checkboxes form element returns its value: an array where the keys are the option storage values, and the values are either 0 for unchecked, or the key for checked.

> I guess we sloud escape the dot at the time the filter is saved.

Another option would be to process the checkboxes element value into a numeric array of the checked values, in other words:

array_values(array_filter(form values))
Lendude’s picture

Here are some failing tests for the handler that is used in the steps described by @joachim in #5 (list_field) and the base handler (in_operator).

Lendude’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 9: option_with_period-2780869-9-TEST_ONLY.patch, failed testing.

dhrjgpt2005@gmail.com’s picture

Assigned: Unassigned » dhrjgpt2005@gmail.com
dhrjgpt2005@gmail.com’s picture

I think to replace "." with anyother character will require lot more changes into core functions like set, validate,setData etc...
While other options suggested by @joachim would be better option and we should give a try.

@Lendude / @dawehner what you suggest on this?

joachim’s picture

I occurs to me that we should compare how other module store a value that's from a form checkboxes element.

For instance, Menu UI module has a checkboxes form element in the node type settings. Those get saved like this:

third_party_settings:
  menu_ui:
    available_menus:
      - footer
      - main
    parent: 'main:'

So filtering as I suggested in #8 does look like the right thing to do.

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.

dhrjgpt2005@gmail.com’s picture

Assigned: dhrjgpt2005@gmail.com » Unassigned

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.

dakku’s picture

Subscribe++

KilianM’s picture

Subscribe
Need a fix

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.

matt_paz’s picture

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

Just updating the target version.

matt_paz’s picture

matt_paz’s picture

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

Updating target

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.

claudiu.cristea’s picture

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

This is a bug. It's 8.9.x

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
4.94 KB

Rerolled the TEST ONLY patch from #9.

Status: Needs review » Needs work

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

claudiu.cristea’s picture

Priority: Normal » Major
Status: Needs work » Needs review
FileSize
7.62 KB
10.61 KB

Here's a fix. I wonder if we need to provide an update path. Any thoughts?

Also, this is Major as it breaks the ability so save a View in such circumstances.

claudiu.cristea’s picture

FileSize
32.29 KB
23.2 KB

Added an update path. Fixing default configs.

The last submitted patch, 30: 2780869-30.patch, failed testing. View results

Status: Needs review » Needs work

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

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
3.99 KB
34.7 KB

Made the check faster in ViewsConfigUpdater (this also fixes a lot of tests).

claudiu.cristea’s picture

FileSize
977 bytes
34.61 KB

Forgot a copy/paste leftover.

Status: Needs review » Needs work

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

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
6.44 KB
38.18 KB

Fixing all failed tests.

claudiu.cristea’s picture

Optimize the ViewsConfigUpdater to avoid creating a plugin instance.

claudiu.cristea’s picture

Adding some return types. Reorder the methods inside ViewsConfigUpdater

Lendude’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Updated the IS a bit to make the problem and proposed solution a bit clearer

The patch looks really good, nothing to nitpick. We have a fix, tests for the fix, update path and test for the update path.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

This patch needs a reroll. The solution does indeed look really nice.

+++ b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php
@@ -155,7 +155,6 @@ public function testFilterQuery() {
-    $view = Views::getView('test_filter_in_operator_ui');

This seems out-of-scope. We need to work why this variable is unused.

+++ b/core/modules/views/src/Plugin/views/filter/InOperator.php
@@ -309,15 +309,13 @@ public function acceptExposedInput($input) {
     // Drupal's FAPI system automatically puts '0' in for any checkbox that
-    // was not set, and the key to the checkbox if it is set.
-    // Unfortunately, this means that if the key to that checkbox is 0,
-    // we are unable to tell if that checkbox was set or not.
+    // was not set, and the key to the checkbox if it is set. Unfortunately,
+    // this means that if the key to that checkbox is 0, we are unable to tell
+    // if that checkbox was set or not.
 
-    // Luckily, the '#value' on the checkboxes form actually contains
-    // *only* a list of checkboxes that were set, and we can use that
-    // instead.
-
...
+    // Luckily, the '#value' on the checkboxes form actually contains *only* a
+    // list of checkboxes that were set, and we can use that instead.

The comment changes here seem out-of-scope. It looks like the comments have not changed at all. Only the code has. Making changes like this increases reviewer load.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
1.99 KB
36.87 KB

Weird, the patch applied cleanly against 8.9.x. Maybe you tried against 9.1.x? As this is a bug I think it should be 8.9.x.

This seems out-of-scope. We need to work why this variable is unused.

During development, I had that test failed. I've noticed the unused variable. Added back.

The comment changes here seem out-of-scope. It looks like the comments have not changed at all. Only the code has. Making changes like this increases reviewer load.

True, the code line is the only one in the method. The comment looks a little untidy as it comes to our coding standards. Reverted.

claudiu.cristea’s picture

Issue tags: -Needs reroll

Removing the tag

alexpott’s picture

@claudiu.cristea we have to commit the fix to 9.1.x first. So we need a 9.1.x patch before we can fix this on any other branch. Also as this contains an update function it'll need special consideration for backport to 8.9.x and 9.0.x. i.e release manager approval.

claudiu.cristea’s picture

Version: 8.9.x-dev » 9.1.x-dev
FileSize
36.49 KB

OK. I'm not up-to-date with the rules on D8>D9 transition. Here's the 9.1.x patch.

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Nice, feedback addressed, back to RTBC assuming this comes back green

claudiu.cristea’s picture

Tagging for 8.9.x backport.

alexpott’s picture

Title: Cannot save a view where a filter value option contains a period » [backport] Cannot save a view where a filter value option contains a period
Version: 9.1.x-dev » 9.0.x-dev

Committed 104bca1 and pushed to 9.1.x. Thanks!

Going to dicuss with other committers about the backport situation.

  • alexpott committed 104bca1 on 9.1.x
    Issue #2780869 by claudiu.cristea, Lendude, joachim, jmadden27: Cannot...
catch’s picture

So the config update function looks fine, but there are quite a lot of changes here overall including a new public method on a class.

alexpott’s picture

@catch yes but it is a new method on a plugin - something that is declared as @internal and not covered by our BC promise.Yes we go out of way to not break stuff but at the same time this bug has no work around.

alexpott’s picture

Title: [backport] Cannot save a view where a filter value option contains a period » Cannot save a view where a filter value option contains a period
Version: 9.0.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/views/src/Plugin/views/filter/Bundle.php
    @@ -128,7 +128,7 @@ public function calculateDependencies() {
    -    foreach (array_keys($this->value) as $bundle) {
    +    foreach ($this->value as $bundle) {
    

    While reviewing this for backport I've got more and more concerned about potential BC impacts of this change. If we need to make this fix here - then what about contrib. InOperator is extended from a lot - see http://grep.xnddx.ru/search?text=InOperator&filename= - so there's a very good chance of this causing issues.

    I think we need to consider only fixing the configuration but maintaining the same structure once the config is loaded. We did something similar for fields and list values.

  2. +++ b/core/modules/views/src/ViewsConfigUpdater.php
    @@ -477,4 +494,49 @@ protected function mapOperatorFromSingleToMultiple($single_operator) {
    +      // Only process if the keys are the same as the values.
    +      if ($values === array_keys($handler['value'])) {
    

    This conditional part gives me concern too. Why is this necessary? If someone resaved a view via the UI isn't the array_values() going to kick in the keys be ignored. Or does this exist to make this reentrant? So we can tell a fixed array from a not fixed one? If so I think we should consider documenting this different.

    Also I think we should check the class before checking the values as that is more logical and less surprising. It might not be as performant but I'm not sure that it matters too much - or if it really is more performant this way around.

Given the BC concerns in point 1 and after discussions with @catch I've decided to revert this for now. Better than regretting it later. It'd be great if people who've worked on the issue can have a think about contrib and possible BC impacts and ways we can mitigate them. Sorry doing the revert but I think it's the best course of action given the concerns.

  • alexpott committed 661d8a8 on 9.1.x
    Revert "Issue #2780869 by claudiu.cristea, Lendude, joachim, jmadden27:...
claudiu.cristea’s picture

I think we need to consider only fixing the configuration but maintaining the same structure once the config is loaded. We did something similar for fields and list values.

@alexpott, could you, please, point me to code for fields and list values?

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.

manjushp’s picture

Based on comment #45, I patched up all the 37 files and I still get the same error
Drupal\Core\Config\ConfigValueException: es_attachment.data key contains a dot which is not supported. in Drupal\Core\Config\ConfigBase->validateKeys() (line 211 of /opt/rh/httpd24/root/var/www/html/dcu/web/core/lib/Drupal/Core/Config/ConfigBase.php).
I just updated my core to 9.2-dev

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.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.