Problem/Motivation

While working on #2976147: Create a sales report supporting daily, weekly, monthly, and yearly breakdowns., my tests failed due to configuration schema validation.

Schema errors for views.view.sales_report with the following errors: views.view.sales_report:display.default.display_options.fields.report_id.set_precision missing schema

The report_id is the entity identifier base field. The View has aggregation enabled, and the report_id is set to COUNT.

In Views, the handler is swapped to numeric as an override when the display is built. This is causing a SchemaIncompleteException exception to be thrown.

This following code is what changes the handler and causes the schema error

\Drupal\views\Plugin\views\display\DisplayPluginBase::getHandlers

        // If aggregation is on, the group type might override the actual
        // handler that is in use. This piece of code checks that and,
        // if necessary, sets the override handler.
        $override = NULL;
        if ($this->useGroupBy() && !empty($info['group_type'])) {
          if (empty($this->view->query)) {
            $this->view->initQuery();
          }
          $aggregate = $this->view->query->getAggregationInfo();
          if (!empty($aggregate[$info['group_type']]['handler'][$type])) {
            $override = $aggregate[$info['group_type']]['handler'][$type];
          }
        }

Steps to reproduce

Create test view, showing content of any type. Enable aggregation. Add field 'Content: ID' and set COUNT type of aggregation on added field.

Proposed resolution

Update logic of manipulating on 'plugin_id' option and change corresponding code, so plugin_id reflects actual state of the field.

Remaining tasks

Review patch/MR, give feedback, rework, accept.

CommentFileSizeAuthor
#58 2976616-58.patch178.6 KBilya.no
#56 interdiff-20-56.txt2.96 KBilya.no
#56 aggregated-entity-fields-cause-schema-exception-2976616-56.patch8.88 KBilya.no
#51 2976616-paliative-51.patch863 bytesvacho
#50 view-gui.png110.21 KBvacho
#50 config-view.png309.14 KBvacho
#48 reroll_diff_42-48.txt17.03 KBAkram Khan
#48 2976616-48.patch184.29 KBAkram Khan
#45 interdiff-2976616-42_45.txt1.92 KBAnchal_gupta
#45 2976616-45.patch184.49 KBAnchal_gupta
#42 2976616-42.patch184.51 KBvacho
#40 2976616-40.patch345.27 KBvacho
#33 2976616-33.patch187.46 KBsolotandem
#31 2976616-31.patch185.47 KBsolotandem
#29 2976616-29.patch182.88 KBsolotandem
#27 2976616-27.patch181.65 KBsolotandem
#26 2976616-26.patch218.85 KBsolotandem
#24 2976616-24.patch3.52 KBsolotandem
#20 2976616-20.patch9.08 KBalexpott
#20 2976616-20.test-only.patch8.08 KBalexpott
#11 aggregated-entity-fields-cause-schema-exception-2976616-11.patch1020 bytesilya.no

Issue fork drupal-2976616

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Issue summary: View changes
Lendude’s picture

Does this only happen in a test or does it also happen when you try to save the View (which is when the config gets validated in a non-test scenario)?

mglaman’s picture

It only happens when running a test which installs the configuration. There is no UI issues, but I think the bigger issue is that this may highlight a gap in test coverage. That's the only time the schema checker runs. The config is valid technically (0 could pass as false) but not against the defined schema.

tim.plunkett’s picture

Unless \Drupal\Core\Config\Development\ConfigSchemaChecker is added as an event subscriber, config schema exceptions will not be raised at runtime.

This is is done for Kernel and Functional tests, which is why schema errors are commonly not found until such a test is written.

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.

pmate’s picture

I can confirm this bug on Drupal 8.6.10 when running functional tests.

I have a view with aggregation enabled and use MIN and MAX on some fields.
--

Edit: It looks like when using aggregation, the views are being saved with data of multiple schema at the same time when (I assume) they only support a single one.

In my case, fields had a `date` plugin_id and when I enabled MIN or MAX aggregation on them they were "converted" to `numeric`. This caused the options to be saved for both plugins under the same "plugin_id" which is breaking the schema.

I have no knowledge here, but shouldn't these type options be saved separately in an array? Both types are valid and all the options saved seems also required but the way it saves is causing the bug.

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.

ilya.no’s picture

Attaching patch with simple solution of adding missing fields into views_field type, which is common for other views fields. It's not clean, but at least has some logic. Another solution is to change whole override functionality, we even have corresponding comment in \Drupal\views\Plugin\ViewsHandlerManager::getHandler(), saying // @todo This is crazy. Find a way to remove the override functionality.
But I'm not sure, whether this type of change is in scope of this issue.

ilya.no’s picture

Status: Active » Needs review
vacho’s picture

Status: Needs review » Needs work

Hi here!

I reviewed the patch and this works well!

However, I have an observation.

The module commerce_reports (https://www.drupal.org/project/commerce_reports) has the view views.view.sales_report.yml that has the fields set_precision, precision, etc.

So I think that the scheme configuration solution that has patch #11 is needed to implement into the commerce_reports module more than views core module.

ilya.no’s picture

Status: Needs work » Needs review

Thanks for the review. commerce_reports module is only example. Actually you can reproduce this issue by creating test view, showing content of any type, adding field Content: ID, enabling aggregation and setting COUNT type on added field. Then you will see error in configuration, saying missing schema.

sorlov’s picture

I think, adding aggregation fields to schema of views_field type from patch #11 makes sense. This way, schema fix will be applied to any field with aggregation.

mparker17’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm the patch in #11 works for me, and passed my code review!

Boldly marking as RTBC.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update, +Needs tests

Lets put the solution into the IS and skimming the issue there are steps to reproduce in #14 which should be in the IS as well.

The remaining tasks indicates that a test is to be written yet there are no tests here, adding tag.

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.

alexpott’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
8.08 KB
9.08 KB

Here's a test. Thanks for the patch @ilya.no!

The last submitted patch, 20: 2976616-20.test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 20: 2976616-20.patch, failed testing. View results

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.

solotandem’s picture

Status: Needs work » Needs review
FileSize
3.52 KB

The comments above note the saved config is not in sync with the schema definitions. The straightforward approach seems to be to keep them in sync. This is easily done by changing the plugin_id when the config is saved.

The $all parameter to unpackOptions should not be TRUE by default. This enables the contamination of config with items from two schema definitions. Setting it to FALSE allows views to prune items no longer applicable to the handler.

public function unpackOptions(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE)

Status: Needs review » Needs work

The last submitted patch, 24: 2976616-24.patch, failed testing. View results

solotandem’s picture

Status: Needs work » Needs review
FileSize
218.85 KB

The test errors were nearly all due to data that is out of sync with the code change. In other words, default module views and test module views need to be updated to reflect the config changes. This includes views in a tar.gz file for testing.

It might make sense to split the patch over new issues:
1) add plugin_id to defineOptions() and schema.yml file
- this requires moving plugin_id in existing default views (regular and test modules)
- this is not directly the topic of this issue but collateral damage of fixing it

2) code change to update plugin_id when grouping applies

solotandem’s picture

Status: Needs review » Needs work

The last submitted patch, 27: 2976616-27.patch, failed testing. View results

solotandem’s picture

Status: Needs work » Needs review
FileSize
182.88 KB

Add more undefined keys used in code and in tests; not in schema.yml files.

Status: Needs review » Needs work

The last submitted patch, 29: 2976616-29.patch, failed testing. View results

solotandem’s picture

Status: Needs work » Needs review
FileSize
185.47 KB

To reiterate, since patch in #24, the test errors are all due to 1) missing schema, 2) code and schema not being in sync, and 3) errors in default views.

Latest patch:
- adds more undefined keys used in code and in tests; not in schema.yml files
- syncs code with schema
- fixes default views

Status: Needs review » Needs work

The last submitted patch, 31: 2976616-31.patch, failed testing. View results

solotandem’s picture

Status: Needs work » Needs review
FileSize
187.46 KB

More of the same.

solotandem’s picture

Issue tags: +Bug Smash Initiative
andypost’s picture

Status: Needs review » Needs work

NW for issue summary update

solotandem’s picture

@andypost Have you read the related issue 3258664? It has the issue summary update. This issue is RTBC in reality.

andypost’s picture

@solotandem yes, but "no idea" as proposed will not work for commiters

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.

vacho’s picture

This is only a rebase for now.

andypost’s picture

@vacho your patch contains lots of unrelated changes, please clean-up it and reupload

vacho’s picture

Yea @andypost, thanks to this catch.

Now yes, a good rebase.

vacho’s picture

Also looks right

/v/w/h/contributedrupal10 (10.1.x|●33…) $ drush cr
 [success] Cache rebuild complete.
/v/w/h/contributedrupal10 (10.1.x|●33…) $ drush config:inspect --only-error --detail
 ----- -------- 
  Key   Status  
 ----- -------- 
andypost’s picture

Status: Needs work » Needs review

issue summary still needs update

Anchal_gupta’s picture

i have fixed cs error.Please review it

Status: Needs review » Needs work

The last submitted patch, 45: 2976616-45.patch, failed testing. View results

andypost’s picture

2 tests still broken and not clear how it will work for existing sites/views

Akram Khan’s picture

Updating patch for 10.1.x and Fixing Custom comand failed #47

vacho’s picture

After review, the last patch needs these works:

- Removes all code comments. Also, explain what the task remains to fix on these.
- Is not clear to me: why changing the order of the plugin_id: field to the first position fixes something.

As I see this looks like the path to fix this issue:
- After saving the view (with aggregation and...) at a time to export the views configuration, this should reflect the plugin_id that views use internally, also the schema should cover this scenario when some item turns as aggregation.

Also one note: Currently, with the last code of Drupal10 I don't get the issue creating a view as #14 explains, how to reproduce. Can some check if still happens and comment on the exact steps to reproduce it?

vacho’s picture

FileSize
309.14 KB
110.21 KB

Related to that I can't reproduce the issue anymore.

I follow these steps:
- Create a view for filter fields for Basic page CT
- Let only a field for Content ID
- Add Aggregation - Count for this field.

This is the git diff for view configuration and these don't throw a config inspection issue.
Not that any field changes of the type.

Config view

this is the view configuration by GUI:

Config view

maybe the issue doesn't happen anymore?

vacho’s picture

This is only a palliative solution. I found this issue in a doesn't upgraded to D10 project.

So this hack propose: If the view field change to numeric, and the schema doesn't chain, the view field can contain these keys(for numeric) also and this can avoid the issue.

These case for schemes with fields that not always be used, was used before on Drupal. So it is no a crazy solution.

andypost’s picture

Issue tags: +Needs tests

Good point with schema but it means we have no test coverage for this handler, IS also needs update

ilya.no’s picture

Status: Needs work » Needs review

I've tested on D10 site and haven't reproduced issue neither. I think, that patch from comment #51 is enough for sites, using D9, while issue itself may be closed.

smustgrave’s picture

Status: Needs review » Needs work

Still needs tests and an issue summary.

If not an issue for 10 then that should be documented in the code and version of the ticket changed.

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.

ilya.no’s picture

Version: 11.x-dev » 10.2.x-dev
Issue summary: View changes
Status: Needs work » Needs review
FileSize
8.88 KB
2.96 KB

Attaching patch with tests, which are taken from #20 comment. I've also updated issue summary with 2 possible solutions.

needs-review-queue-bot’s picture

Status: Needs review » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

ilya.no’s picture

Version: 10.2.x-dev » 11.x-dev
Issue summary: View changes
Status: Needs work » Needs review
FileSize
178.6 KB

While checking failed tests for my patch, I've discovered following points:
1) My solution doesn't work for latest versions of Drupal, because it adds more mess into config schema definition and it affects views more heavy, than I've expected, so I've focused on another solution of that issue.
2) I've put a bit wrong description on `Steps to reproduce` section. If we create field and then enable aggregation, than issue is not reproduced. But if we create view, enable aggregation, add field and set its aggregation to COUNT, than issue can be reproduced with latest version of Drupal. So we first need to enable aggregation and only then add field and set aggregation for it.

I've fixed `Steps to reproduce` section and also removed my solution from `Proposed resolution` section. I'm adding new patch, which is rebase of the patch from 33 comment. I couldn't generate interdiff, but basically it's rebase for D11 with couple of fixes. I've also added hook_post_update. I haven't run all tests, but the ones, which were failing are now good, at least locally.

ilya.no’s picture

I've created MR with changes from latest patch for further developing.

andypost’s picture

Thank you 🙏 Is there a way to prevent reordering in yml files?

ilya.no’s picture

As I understand no, because currently different mappings in schema contain plugin_id in their own place. In this issue we remove plugin_id from all these mappings and add it to the `views_handler` type at the first place.

Basically we don't need to reorder it for existing views, but we need to update default views from core modules, because otherwise tests fail. It happens, because test compares default config with actual and fails, as they are not the same.

I've pushed phpcs fix into MR, not sure, that I need to update patch for it.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs upgrade path tests

Appears to have test failures. Also believe we will need a simple test for the post_update hook.