EntityViewsData is broken for fields with 'numeric' columns, such as decimal fields (DecimalItem)

Created on 22 June 2015, over 9 years ago
Updated 12 July 2024, 6 months ago

Problem/Motivation

EntityViewsData generates incorrect data for entities that have fields which have numeric schema columns.

Instead of the numeric argument and filter, the standard ones are used.

This breaks at least exposed filters, I haven't tested anything more specific.

Proposed resolution

EntityViewsData contains the following (starting at line 395):

        switch ($column_type) {

          case 'int':
          case 'integer':
          case 'smallint':
          case 'tinyint':
          case 'mediumint':
          case 'float':
          case 'double':
          case 'decimal':
            $views_field['field']['id'] = 'field';
            $views_field['argument']['id'] = 'numeric';
            $views_field['filter']['id'] = 'numeric';
            $views_field['sort']['id'] = 'standard';
            break;

          ...

        }

The $column_type for decimal columns is numeric, though, not decimal. I think decimal doesn't actually exist.

Fix the condition to catch numeric columns.

Remaining tasks

User interface changes

API changes

Data model changes

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated about 10 hours ago

Created by

🇩🇪Germany tstoeckler Essen, Germany

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇮🇳India nikhil_110

    Attached patch against Drupal 10.1.x

  • 🇷🇺Russia kvantstudio

    Patch #37 work fine! I think this is a serious problem for all sites where entities work with money. I solved this problem for myself by changing the array in get Views Data in the 'view_builder' entity handler.

      /**
       * {@inheritdoc}
       */
      public function getViewsData() {
        $data = parent::getViewsData();
    
        // TODO: added before fix Drupal core https://www.drupal.org/project/drupal/issues/2509986
        $data['site_commerce_product__price']['price_number_from']['filter']['id'] = 'numeric';
        $data['site_commerce_product__price']['price_number']['filter']['id'] = 'numeric';
        $data['site_commerce_product__price']['price_number_sale']['filter']['id'] = 'numeric';
    
        return $data;
      }
    
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States mlncn Minneapolis, MN, USA
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Previously tagged for upgrade paths and tests which are still needed

  • last update about 1 year ago
    30,437 pass
  • 🇷🇺Russia Chi

    To summarize. The requirement for upgrade path made this bug unfixable. Updating existing configuration especially Views is tricky and can cause more problems. I think changes without upgrade path should be allowed in major Drupal release. Otherwise this bug will likely exist forever.

Production build 0.71.5 2024