I have been testing some importing via Feeds with Feed Tamper. I have used this successfully many times using Drupal 7 -- but for the dev-release for Drupal 8 is tossing this error:

Drupal\tamper\Exception\TamperException: Input should be a string. in Drupal\tamper\Plugin\Tamper\Explode->tamper() (line 80 of /modules/tamper/src/Plugin/Tamper/Explode.php).

I am looking at the exports and have tried comma separate, tabbed, and pipes. Nothing in the data should cause this (that I can tell).

Comments

Shane Birley created an issue. See original summary.

shane birley’s picture

I also just noticed (after posting) that it is referring to the Tamper module, I think.

megachriz’s picture

Status: Active » Postponed (maintainer needs more info)

This can happen if you put certain tampers in a row or if the value coming from the import source is already an array. The Explode plugin expects a string as input.

Can you share your feed type and the data you are trying to import?

shane birley’s picture

The CSV file I am using is a cleaned up export from an old Drupal 6 site. The terms I am attempting to import look like:

tag 1|tag 2|tag 3

These are in a basic cell on the spreadsheet. I must be missing something basic here... just not seeing it.

megachriz’s picture

Maybe you added tamper plugins for a source and later removed that source from the mapping? Therefore: can you provide an export of your feed type?

You can put one in a Features module or you can export it using the config manager.

Note: I'm about to commit a fix for the issue of tamper plugins that kept existing even after changing the mapping. See #2974289: Remove tamper plugin instances when source is removed.

shane birley’s picture

There were a couple of times where the config for the tamper mapping "vanished". I thought maybe I had removed the config or had forgotten to save it. But when trying to figure out what was going on, I did add and remove the setup a couple of times as well. My problem might be what you've described.

Let me check out the patch and see if that makes a difference.

saratt’s picture

Hi Shane,

Were you able to figure out what the problem was? I am running into the same issue.

shane birley’s picture

Hey, @st55:

I haven't had a chance to test it as have been working on some other pieces of the project. I will test it over the next couple of days. I think the patch that @MegaChriz posted is actually the problem.

Have you applied the patch?

megachriz’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

I assume #2974289: Remove tamper plugin instances when source is removed fixes this issue. If not, please reopen.

rongok’s picture

Status: Closed (works as designed) » Active

The patch that @MegaChriz posted didn't fix the issue. Still get the error when exploding comma separated string and when converting string to unix time.

andrenoronha’s picture

I've got the same bug but when trying to use any plugin to any source. It always tells me that my piece of text is not a string (and it should be).

The most strange thing is that I have already imported with success lots of content from different feed types. And now even the old ones are bringing me the same problem.

philbi’s picture

This issue can happen if the explode function is applied on an empty string.

rongok’s picture

Status: Active » Closed (works as designed)

It works if the header name of the CSV is same as machine name of the source.

kobb’s picture

This issue can happen if the explode function is applied on an empty string. - @philbi

I'm sure that I missed something, and this is not best practice, but this modified Explode.php tamper function is a temporary fix for those in need.

  public function tamper($data, TamperableItemInterface $item = NULL) {
    if ($data == NULL) {
      return FALSE;
    }
    if (!is_string($data)) {
      throw new TamperException('Input should be a string.');
    }
    $separator = str_replace(['%s', '%t', '%n'], [' ', "\t", "\n"], $this->getSetting(self::SETTING_SEPARATOR));
    $limit = is_numeric($this->getSetting(self::SETTING_LIMIT)) ? $this->getSetting(self::SETTING_LIMIT) : PHP_INT_MAX;
    return explode($separator, $data, $limit);
  }

The only change is the addition of the first if statement.

EDIT: I just realized this is the issue queue for feeds_tamper not tamper. This function is for the tamper module.

adamevertsson’s picture

I don't know if it helps, but I got multiple taxonomy term import via Feeds to work when I patched Feeds with the patch at https://www.drupal.org/project/feeds/issues/2453123
Don't need to user Feeds tamper for this with the patch (https://www.drupal.org/files/issues/2019-01-25/2453123-6.patch), actually if you add the Feeds tamper plugin Explode with the patch applied you get no result, but with no plugin applied to the data with many terms it works.

// Adam

bmenk’s picture

Did this ever get a more permanent fix than the little code snippet mentioned in #14? That works for me but of course will be an issue for new updates etc. I'm presently running 8.x-2.0-beta1 and it did not look like anything in the explode.php code had changed at all.
Thanks for any advice on a longer term fix.

Bobb Menk

AdrianoMoura’s picture

best way to remove blanks in the return of Explode->tamper( ...

return array_map( "trim", explode($separator, $data, $limit) );
potassiumchloride’s picture

@andrenoronha I'm having the same problem. I've been using Feeds and Feeds Tamper for months and now I suddenly have this issue. Any advice?

mslaxmeter’s picture

I can also confirm the issue. I have a feed set up to import CSV data, with an Explode tamper on a specific column.

When I import an empty or valid string it seems to work fine, but if I import a sheet that doesnt include the tampered column (I don't want to update items with an empty value), I get HTTP 500 during import and the same message as the reporter.

I agree this should be a fix put into the module instead of a custom code snippet.

mslaxmeter’s picture

Category: Support request » Bug report
Status: Closed (works as designed) » Needs review
ericgsmith’s picture

Linking related issue in tamper module. It seems there is a lot of support to improve the handling of null values. Please see the issue Improve handling of empty data. It would be awesome if that issue could get some feedback.

The change in #14 is essentially part of that issue - I would also welcome that as a standalone patch in tamper module.

lissy’s picture

A Workarround is, to integrate the Tamper "Skip tampers on empty" and put it before the Explode-Tamper

ron collins’s picture

In case this helps someone else, I got this error when I accidentally selected a mapping for a new blank source instead of a new CSV source.

benstallings’s picture

Status: Needs review » Closed (works as designed)

There doesn't appear to be anything to review in this ticket.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.