Follow-up to #1851398: PDOException:Invalid text representation when attempting to load an entity with a string ID

Postponed on #1851398: PDOException:Invalid text representation when attempting to load an entity with a string ID

By @joelpittet:

It may be good to log the error as it seems likely that there may be an error in code that is passing values up the stack. At least array_flip errors seem to be popping up like that for me;)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RoySegall’s picture

I got the same issue in OpenScholar with migration. I'm attaching a small patch which based on #1102570: array_flip() [function.array-flip] issue in DrupalDefaultEntityController / entity.inc

RoySegall’s picture

Status: Postponed » Needs review
stefan.r’s picture

Status: Needs review » Needs work

That's not "logging an error" ;)

Have a look at entityCacheCleanIds

Are you using the 1.5 version?

RoySegall’s picture

Yap.

tempo22’s picture

Is this regarding the "Warning: array_flip(): Can only flip STRING and INTEGER values!" warnings that started to appear with last version ?

I'm running the 7.x and since last version, my logs are filled with thoses warning. I never bothered since the website was running well anyway.

joelpittet’s picture

It usually turns out there is some bad code (either yours or contrib) if you see this happen but it's kind of tricky to debug.

The last time I saw this array_filter($ids, 'strlen') didn't work because the $ids was an accidental array passed into node_load($nid = array(1234));.

Putting in a decent check would be a nasty performance hit I'd assume...

tempo22’s picture

Yes, i don't mind fixing the code making the bad code but it's hard to figure where it is :(

joelpittet’s picture

Setting a breakpoint and looking at the $ids helped and up the callstack

michaellenahan’s picture

Setting a breakpoint and looking at the $ids helped and up the callstack

A few notes to explain what @joelpittet means here.

It is very likely that the error is in your own custom code. Here's how I found what was wrong in my code.

To do this, you need an IDE such as PHPStorm, so that you can debug and set breakpoints. I'm using PHPStorm.

In my case, the error was coming from line 73 of entitycache.entitycachecontrollerhelper.inc - see Screenshot: https://www.drupal.org/files/issues/how-to-fix-can-only-flip-string-and-...

I put a conditional breakpoint on the next executable line (for me, this was line 78 if ($conditions) {). This conditional breakpoint had the Condition empty($passed_ids) - doing this means the breakpoint gets hit far fewer times.

When the breakpoint hits, look in the Frames to see if you can find any of your own custom code. In my case it was a user_load() call where the $uid was NULL. See Screenshot: https://www.drupal.org/files/issues/go-up-the-frame.png

joelpittet’s picture

@michaellenahan thanks, I rarely give enough information;)