A loose type comparison in EntityDrupalWarpper::set() incorrectly equates 0 = null. as a result is fails to update the parent EntityDrupalWrapper object and the authorship stays as the old value.

The solution is a contender for trivial patch of the month club but took the better part of the afternoon to track down ;). Im not much of a "mark it as critical" guy but this one seems appropriate.

Comments

DaneMacaulay’s picture

Test case:

  // test via setting author directly
  $node = entity_create('node', array('uid'=>1, 'title'=>'test', 'type' => 'page'));
  node_save($node);
  $node_wrapper = entity_metadata_wrapper('node', $node->nid);
  $node_wrapper->author = 0;
  $node_wrapper->save();
  $node = node_load($node->nid, null, true);
  print('Node uid:' . $node->uid); //should print 0 but prints 2

  //test via set()
  $node = entity_create('node', array('uid'=>1, 'title'=>'test', 'type' => 'page'));
  node_save($node);
  $node_wrapper = entity_metadata_wrapper('node', $node->nid);
  $node_wrapper->author->set(0);
  $node_wrapper->save();
  $node = node_load($node->nid, null, true);
  print('Node uid:' . $node->uid); //should print 0 but prints 2
DaneMacaulay’s picture

Status: Needs review » Reviewed & tested by the community
fago’s picture

Status: Reviewed & tested by the community » Fixed

I don't think it's critical as it doesn't render the module unusable, but anyway - good catch, committed thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Paul B’s picture

Status: Closed (fixed) » Active
Issue tags: -Trivial patch of the month, -trivial +Regression

This patch is causing some problems for me. I'm using the Relation
module with the patch in #1958298: Relation property on entity_metadata_wrapper().

I have a Treatment entity that is related to a Profile through a treatment_has_carer Relation.
The Relation has a field that is set to 0 when the status of the Treatment changes:

      { "LOOP" : {
          "USING" : { "list" : [ "treatment:relation-treatment-has-carer" ] },
          "ITEM" : { "has_carer_relation" : "has_carer relation" },
          "DO" : [
            { "data_set" : { "data" : [ "has-carer-relation:field-actief" ], "value" : 0 } },

With the patch, this no longer works. For example, I have treatment 56 that has relation 95:

% drush ev '$t=treatment_load(56); $w= entity_metadata_wrapper("treatment", $t); $w->relation_treatment_has_carer[0]->field_actief->set(0);'
WD php: EntityMetadataWrapperException: Entity property relation_treatment_has_carer doesn't support writing.

It seems that in EntityDrupalWrapper::set(), the $previous_id is 95,
but $this->id is "95". So it now calls updateParent(), which fails. If
I add a setter callback to the property info in #1958298: Relation property on entity_metadata_wrapper() it
succeeds, but this property should be read-only as it's not a 'real'
property.

Paul B’s picture

Status: Active » Needs review
StatusFileSize
new551 bytes

The patch should fix it.

Paul B’s picture

StatusFileSize
new555 bytes

reroll.