Search code examples
drupaldrupal-7

EntityMetadataWrapperException: Invalid data value given


On editing a node with a user of a particular role i get the following error a Drupal site. With only user 1 it works. Can't figure why. I debug the entity file, but it seems that the id disappear after iteration.

EntityMetadataWrapperException : Invalid data value given. Be sure it matches the required data type and format. dans EntityDrupalWrapper->set() (ligne 737 dans /sites/all/modules/entity/includes/entity.wrapper.inc).

No coding yet has been done for this only using contrib modules.


Solution

  • Since you haven't done any coding, it's probably bug of some contrib module, Entity API or you're dealing with malformed entity.

    Try applying this patch: Add field information to exception message on validation exception, this will allow you to see on which value it fails.

    In case you're using some custom coding, then check Entity metadata wrappers page for some examples. The common mistake is to not use array() for set() when dealing with multi-valued field, or opposite - extra array for single-valued field.

    If you can reproduce the problem, you can debug the issue either by step-by-step debugger and do the breakpoint on Exception line, or do it manually by temporary adding: var_dump(debug_backtrace()); exit; just before the exception happens, so PHP can dump the backtrace of your current code with all the argument passed, so you can track your malformed entity or identify the failing contrib module.

    See also: How to set a value on a field collection using entity metadata wrapper at DA