NULL delta displayed as 0

Created on 3 August 2022, almost 3 years ago
Updated 10 June 2025, 26 days ago

Problem/Motivation

It would be useful to distinguish between a field that has no value for a given entity and a field that has one value (delta 0). However, Views displays a NULL delta as 0 even when "Hide if empty" is checked and "Count the number 0 as empty" is not checked.

Steps to reproduce

I encountered this with Layout Builder, where there is no actual field value to test on, so that's the example I'll give. Enable Layout Builder and add a layout for a node. Edit the /admin/content/node View and add the layout_builder__layout:delta field. Note that it displays 0 for the nodes that have no layouts as well as for the node that has a layout. (If the node has more than one layout, it will appear once for each delta.)

Now try editing the field settings in the View and under No Results Behavior, check the box for "Hide if empty." Do not check the box for "Count the number 0 as empty." Apply changes, and you will see all the 0s hidden, including the one that is actually 0 and not NULL.

Now go to /web/admin/structure/views/settings and enable "Show the SQL query." Go back to your View and copy the query. Strip the quotes and curly brackets and run the query directly on your database. Note that NULL values are distinct from 0 values.

Proposed resolution

Render NULL values as an empty string. If this would break something, then at least allow for a distinction when "Hide if empty" is checked.

Remaining tasks

I have no idea. Maybe it's in the NumericField plugin?

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

views.module

Created by

πŸ‡ΊπŸ‡ΈUnited States BenStallings

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.

  • πŸ‡ΊπŸ‡ΈUnited States clayfreeman Paragould, AR

    At least as far as I can tell, this appears to be happening because the NumericField views plugin is using strict equality:

        // Check to see if hiding should happen before adding prefix and suffix
        // and before rewriting.
        if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
          return '';
        }
    

    This probably isn't correct, because the value my table returns is a string ('0') even though the column is using an int type.

  • πŸ‡ΊπŸ‡ΈUnited States clayfreeman Paragould, AR
  • πŸ‡¦πŸ‡ΊAustralia sime Melbourne

    I was unable to use the delta to show whether an entity had a layout override because NULL and 0 rendered to 0.

Production build 0.71.5 2024