Hi,

i am using a "geofield field type" with the "from another field widget" from the geocoder modul ( https://drupal.org/project/geocoder ) in one of my bookable unit types from the rooms module to gecode from an address field. First, everything seemed to work fine. But if i add a another bookable unit i get this error:

EntityMalformedException: Missing bundle property on entity of type rooms_unit. in entity_extract_ids() (line 7693 of /var/www/ua-repo/includes/common.inc).

Drupal 7.23
Commerce 7.x-1.8
Rooms 7.x-1.0

CommentFileSizeAuthor
#5 rooms-entity-original-2143515-5.patch932 bytesjwilson3
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ronald_istos’s picture

Status: Needs work » Closed (cannot reproduce)
AdamPS’s picture

Version: 7.x-1.x-dev » 7.x-1.3
Priority: Major » Normal
Status: Closed (cannot reproduce) » Needs work

I can reproduce this error message reliably. I can't say for sure if it's the same bug as the OP, but it's the exact same message, so I thought worth re-opening the issue rather than creating a new one.

In my case there was no geocoder module. I have a standard Rooms install with not much else added.
- Rooms 7.x-1.3
- Drupal core 7.31

Scenario
- Create a unit type and a unit
- Create a booking
- Delete the unit that the booking uses: works fine, no warning that it was in use
- At this point the booking has a blank value for "unit" in the list of bookings
- Try to edit the booking (admin/rooms/bookings/booking/NNNNN/edit)

Expected behaviour
- Perhaps should disallow deleting the room?
- Should be able to edit the booking. In particular might want to assign a unit!

jwilson3’s picture

Status: Needs work » Active

I'm also able to repeat this error while attempting to convert the Waterbed Rooms feature by @enzo to remove the dependency on the rooms_node module, by adding the fields directly to the unit. There are two geo fields I've added to the rooms bookable unit: one is field_address and one is field_address_autocomplete. The field_address is configured to pull the value "from another field widget" (the autocomplete field). When creating the first unit, I get the same error as OP. I wasn't able to take this any further, and not really sure how to go about debugging this.

Steps to reproduce:

  1. Setup local install with waterbed rooms feature.
    $ drush dl drupal-7 && cd drupal-7/sites/all/modules
    $ git clone git@github.com:enzolutions/drupal_waterbed_rooms.git
    $ git clone --branch 7.x-1.x http://git.drupal.org/sandbox/ziomizar/2086255.git rooms_node
    $ drush en waterbed_rooms
    
  2. Add existing picture, address, and address autocomplete fields to both "Standard Double" and "Deluxe Double" room types.
  3. Create a "Standard Double" unit, and click save.
jwilson3’s picture

I've tracked this down to the following lines of code in the geocoder.widget.inc:

    // For entities being updated, determine if another geocode is necessary
    if ($entity) {
      if (!empty($entity->original)) {
        dpm($entity->original);
        //@@TODO: Deal with entity-properties (non-fields)
        //@@TODO: This isn't working with file fields. Should use some kind of lookup / map
        $field_original = field_get_items($entity_type, $entity->original, $field_name, isset($entity->original->language) ? $entity->original->language : NULL);
        if (!empty($field_original)) {
          $diff = geocoder_widget_array_recursive_diff($field_original, $source_field_values);
          if (empty($diff)) {
            return FALSE;
          }
        }
      }
    }

the field_get_items() function expects the second parameter to be an actual entity object, but in this case $entity->original is set to the value TRUE.

I'm currently trying to figure out where $entity->original is being incorrectly set to TRUE in the codebase. This value should either be the unchanged entity object, or FALSE if the entity cannot be loaded, but never "TRUE". Weird.

jwilson3’s picture

@Ronald:

I've tracked this issue down to the RoomsUnitController::create() method, which incorrectly sets a default value for the 'original' member to TRUE. This was introduced by http://cgit.drupalcode.org/rooms/commit/?id=b4fe0ea1.

Coincidentally, RoomsUnitController::create() also has the same issue, introduced by http://cgit.drupalcode.org/rooms/commit/?id=5ba66263.

Removing the lines does fix this error... so here is a patch.

As for why these lines were introduced, I don't know, so it would be good for @Ronald's input on this, to see if it makes sense.

From reading through the entity module codebase, it looks like the unwritten API for the $entity->original field is that it should only be populated when saving new data to an existing entity that already has a primary key, and it should be populated with a copy of the original entity object, using entity_load_unchanged. Otherwise it should be FALSE. it should never be TRUE.

jwilson3’s picture

Status: Active » Needs review
plopesc’s picture

Status: Needs review » Fixed

Thank you @jwilson3. Committed.

Status: Fixed » Closed (fixed)

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