Tamper: "Convert to Boolean" If No Match

Created on 12 May 2022, about 3 years ago
Updated 13 May 2025, about 7 hours ago

Problem/Motivation

Using the feeds tamper to convert text to boolean, I set the "If No Match" to false, but blank fields in the CSV get imported as true.

The config for the tamper within the feed is:

      c4b26c8f-bf74-4ead-b53e-4084e464ed7f:
        true_value: 'y'
        false_value: 'n'
        match_case: false
        no_match_value: 'false'
        other_text: ''
        uuid: c4b26c8f-bf74-4ead-b53e-4084e464ed7f
        plugin: convert_boolean
        source: cataloged
        weight: -9
        label: 'Convert to Boolean'

Steps to reproduce

  1. Create a csv feed with a column to import as boolean that has blank items in it.
  2. Setup a feed using the tamper "convert to boolean" and set the "If No Match" value to false
  3. Import items. The blank items import as true instead of false.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States kwfinken Lansing, MI

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.

  • πŸ‡³πŸ‡ΏNew Zealand thomasmurphy

    I found a similar behaviour with core 11.1.6, feeds 3.0.0, tamper 2.0.0-beta4. Importing a csv value to a boolean, with the convert to boolean tamper, and the no match set to "null" doesn't behave that way. It's defaults to false instead.

    I verified this by creating a test node with the "N/A" value set via the checkbox/radio buttons, and a test view renders the boolean value as blank. The only two outcomes with the tamper "convert to boolean" plug-in is default to true or false. For context I set a test csv value to "NULL" to verify that this wasn't a problem related to an empty string.

  • πŸ‡³πŸ‡±Netherlands megachriz

    If you can write a test that demonstrates the bug, that would be great! The test should be added to \Drupal\Tests\tamper\Unit\Plugin\Tamper\ConvertBooleanTest.

    Since there is a patch, I set the issue status to "Needs work". "active" indicates that there's only a report and no existing code.

Production build 0.71.5 2024