EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 736 of /app/www/d7/ibis/production/sites/all/modules/contrib/entity/includes/entity.wrapper.inc).

This exception occurs with a URL like this: node/32643text

Backtrace from og:
1. og_ui_og_ui_get_group_admin()
2. og_is_group_default_access()
3. entity_metadata_wrapper()
4. new EntityDrupalWrapper()
5. EntityMetadataWrapper::set()
6. EntityMetadataWrapper::validate()
7. entity_property_verify_data_type()
This return FALSE with a path like node/32643%3Fpage%3D1 or node/32643lol but only when node/32643 is valid.

It's being caused by the fact that node_load() works with the gammy path, so you don't get "Page not found", but then entity_property_verify_data_type() fails because it doesn't look like an int (see line 270 of entity.wrapper.inc).

I've identified this bug via og, but presumably it can be caused by other modules as well.

CommentFileSizeAuthor
#8 2214417.diff1 KBdrumm

Comments

mossy2100’s picture

Ok the bug occurs because this code in include/entity.inc works even if id looks like '9999lol':
(lines 184-193)

// Load any remaining entities from the database. This is the case if $ids
// is set to FALSE (so we load all entities), if there are any ids left to
// load, if loading a revision, or if $conditions was passed without $ids.
if ($ids === FALSE || $ids || $revision_id || ($conditions && !$passed_ids)) {
// Build the query.
$query = $this->buildQuery($ids, $conditions, $revision_id);
$queried_entities = $query
->execute()
->fetchAllAssoc($this->idKey);
}
Mysql accepts the value 9999lol as 9999 and the query returns, assuming there is a matching entity with id=9999.
So it's arguably a bug a core - perhaps there should be a check here that $ids contains only ints.

paulovg12’s picture

I have the same issue, I deleted some of the previous contents, ( I believe there was an OG update a few days ago). The OG update was March 18 the update a few days ago was something else maybe Entity API.
Mine use to work fine before the deletion and update.

message is below:

Type node
Date Wednesday, April 9, 2014 - 02:49
User pvgervasio
Location https://secure144.inmotionhosting.com/~dacapo5/rc/node/add/photos?og_gro...
Referrer https://secure144.inmotionhosting.com/~dacapo5/rc/node/add/photos?og_gro...
Message EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 736 of /home/dacapo5/public_html/rc/sites/all/modules/entity/includes/entity.wrapper.inc).
Severity error
Hostname 218.186.196.224
Operations

I did some testing and temporarily modified the I added the following in the entity wrapper inc file :

  public function set($value) {
   if (!$this->validate($value)) {
       drupal_set_message('Entity Wrapper: Invalid data value given: '. $value);
       drupal_set_message('Entity Wrapper: Invalid data value given info [type]: '. $value->info['type']);
       drupal_set_message('Entity Wrapper: Invalid data value given info: '. $value->info);
       drupal_set_message('Entity Wrapper: Invalid data value given type: '. $value->type);
       drupal_set_message('Entity Wrapper: Invalid data value given id: '. $value->id);
       drupal_set_message('Entity Wrapper: Invalid data value given data: '. $value->data);
       throw new EntityMetadataWrapperException('Invalid data value given. Be sure it matches the required data type and format.');
    }

it gave me this

Entity Wrapper: Invalid data value given: Array
Entity Wrapper: Invalid data value given info [type]:
Entity Wrapper: Invalid data value given info:
Entity Wrapper: Invalid data value given type:
Entity Wrapper: Invalid data value given id:
Entity Wrapper: Invalid data value given data:

The value Array in $value is either empty array or the string "Array"

1kenthomas’s picture

Project: Entity API » Organic Groups
Component: Entity property wrapper » og.module

See https://drupal.org/node/1925412 ; moving this to OG queue.

(Likely this is due to OG or another module not sanitizing its data, and should be reported there ...)

shushu’s picture

Status: Active » Closed (duplicate)

Can you verify the proper OG version ?

hiramanpatil’s picture

I am getting error when assigning mulitple roles to the user. If use has single role then page loads properly. But as soon as I assign second role to the user and logs in with same user from front-end it shows below error message:-

EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 736 of /PROJECT_PATH/sites/all/modules/entity/includes/entity.wrapper.inc).

Please let me know if anyone has same issue or any solution.

f1l1pp0’s picture

Version: 7.x-1.3 » 7.x-2.7

I am also experiencing this problem, and I believe the reason is the same as hiramanpatil described: since I gave an additional role to some users, an EntityMetadataWrapperException occurs everytime a user with multiple roles creates a new post (group content).
Did anyone find a solution?
The problem occurs on a Drupal Commons distribution installed a couple of months ago which runs the latest version of Organic Groups.
Thanks!

drumm’s picture

Version: 7.x-2.7 » 7.x-2.x-dev
Component: og.module » og-ui
Assigned: Unassigned » drumm
Status: Closed (duplicate) » Active
Issue tags: +affects drupal.org

#5 and #6 may be a separate issue, I haven't tested users with multiple roles.

The original issue report, “This exception occurs with a URL like this: node/32643text” is affecting Drupal.org. Instead of the regular core behavior of loading up node 32643, this exception happens.

drumm’s picture

Status: Active » Needs review
StatusFileSize
new1 KB

This patch fixes the issue by casting the input to the expected int.

Status: Needs review » Needs work

The last submitted patch, 8: 2214417.diff, failed testing.

drumm’s picture

Assigned: drumm » Unassigned
Status: Needs work » Closed (duplicate)

Actually, this was fixed by #2242237: EntityMetadataWrapperException when OG UI uses invalid group IDs, which has been committed to 7.x-2.x, but is not in 7.x-2.7.