Found on a site using Field Collection-7.x-1.0-beta7.

If you try to delete an entity that have a bunch of field collection items linked to it, then, you get a not so nice Exception thrown in entity_extract_ids. I'm attaching the full exception backtrace to help reviewing, but the short version of what's going on is that the entity deletion triggers the field collection items deletion (as expected). Given that those field collection items are entities too, there deleting also triggers cer_entity_delete, which tries to find their lineage by retrieving the Field Collection hostEntity() and then passing that too entity_extract_id. It fails though, because at that point the Field collection no longer have an host entity in place, which makes cer_get_field_collection_lineage_array blindly call entity_extracs_ids with a null second parameter, leading to the exception being thrown.

Not completely sure what to do ; using $collection->hostEntityBundle(); directly would work around the exception for the simple not nested case, but wouldn't provide a correct lineage either.

Comments

DeFr’s picture

Mentionned backtrace. This is with a Field Collection set up on an entity type created through ECK ; it also happens on Profile 2 profiles when a user account is cancelled and on nodes.

mkeiser’s picture

I am having what appears to be the same issue. It is a content type with a field collection that also contains a field collection. It was preventing me from deleting content of that type. The following appears to fix it in my case (though I am not sure if there are other implications such as possible orphaned field collections or cer references) allowing me to delete the content without error.

--- cer.properties.field_collection.inc (revision 5310)
+++ cer.properties.field_collection.inc (working copy)
@@ -29,6 +29,11 @@

   $data[0] = $collection->hostEntityType();
   $data[1] = $collection->hostEntity();
+
+  if (! $data[1]) {
+    return $options['lineage'];
+  }
+
   list (, , $host_bundle) = entity_extract_IDs($data[0], $data[1]);
   array_unshift($options['lineage'], $data[0] . ":{$host_bundle}:{$collection->field_name}");
fabianderijk’s picture

Status: Active » Needs review
StatusFileSize
new617 bytes

I've created a patch for this fix. For me it solves all issues.

zmove’s picture

Status: Needs review » Needs work
Related issues: +#2352783: Exception thrown when deleting an entity with a field collection

#3 doesn not resolve the issue for me. It throw an exception when I delete a field collection synced with CER :

EntityMetadataWrapperException: Unable to get the data property field_entity_reference as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 438 of /home/www/sites/all/modules/entity/includes/entity.wrapper.inc).
pingevt’s picture

My problem was I had a field collection within a paragraph. Non of these fields had CER attached. Another field within the node that wasn't a field collection or a paragraph bundle was attached. When I tried to delete the node, I received an error which was fixed by #3. So I think the patch in #3 needs to be applied, but more needs to be added if that field has a cer attached to it.

socialnicheguru’s picture

Status: Needs work » Reviewed & tested by the community

The patch solved my issue too.
I simply had cer enabled on my system.
I had an event type with field_collections
Deleting the event would trigger cer delete which throws an exception on the field_collection.

I have not tried the case where a field is in a field_collection and is using cer

fox mulder’s picture

Same problem here and #3 solves it.

My Profile2 type uses field_collection type fields, but these fields are not using cer ( cer is enabled and there are some cer presets configured to other fields ).
I think so the field_collection type fields are or are not using cer presets is irrelevant, because entity_delete() invokes cer_entity_delete() at all events.

I think it's major because it causes mysterious, difficult to debug errors

ironsizide’s picture

This patch solved my problems.
ECK entity with a field collection, CER module installed.
Deleting the event would trigger cer delete which throws an exception on the field_collection.

phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

Three people reporting that the patch fixes their problem, is good enough for me. Committed and pushed -- thanks!

Note to anyone who might need this: it's not in the 7.x-3.0-beta1 release.

Status: Fixed » Closed (fixed)

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