EntityFieldQueryException: Unknown field: field_userref in EntityFieldQuery->addFieldCondition() (line 770 of C:\wamp\www\tta\includes\entity.inc).

The field_userref was deleted from the content type. Now every time I try to delete another field, this happens. Yes, I did clear the cache.

CommentFileSizeAuthor
#7 fieldcol-1866032-7.patch839 bytesklausi

Comments

nancydru’s picture

Priority: Normal » Major
catch’s picture

Status: Active » Postponed (maintainer needs more info)

Please post a backtrace.

nancydru’s picture

I told Devel to create a backtrace, but none came out.

nancydru’s picture

Maybe this will help
# Time Memory Function Location
1 0.0003 680536 {main}( ) ..\index.php:0
2 0.2535 49730512 menu_execute_active_handler( ) ..\index.php:21
3 0.2566 50495696 call_user_func_array ( ) ..\menu.inc:517
4 0.2566 50496096 drupal_get_form( ) ..\menu.inc:517
5 0.2566 50498432 drupal_build_form( ) ..\form.inc:131
6 0.2576 50524096 drupal_process_form( ) ..\form.inc:374
7 0.2593 50574840 form_execute_handlers( ) ..\form.inc:860
8 0.2593 50578248 field_ui_field_delete_form_submit( ) ..\form.inc:1464
9 0.4757 53836264 field_purge_batch( ) ..\field_ui.admin.inc:1791
10 0.5390 56186072 field_purge_data( ) ..\field.crud.inc:870
11 0.5390 56186632 _field_invoke( ) ..\field.crud.inc:910
12 0.5398 56195328 field_collection_field_delete( ) ..\field.attach.inc:209
13 0.5399 56199624 EntityFieldQuery->fieldCondition( ) ..\field_collection.module:633
14 0.5399 56199976 EntityFieldQuery->addFieldCondition( ) ..\entity.inc:663

catch’s picture

Project: Drupal core » Field collection
Version: 7.17 » 7.x-1.x-dev
Component: field system » Code
Status: Postponed (maintainer needs more info) » Active

Yes that helps. Moving to field_collection.

DrupalDan’s picture

I got the same problem. I tried the dev version but the problem persists. Please let me know if you need anything. Thanks!

klausi’s picture

Status: Active » Needs review
StatusFileSize
new839 bytes

Here is a patch that only executes the EFQ if the actual field info still exists, because otherwise that causes the EFQ exception.

andypost’s picture

Makes sense.

+++ b/field_collection.module
@@ -958,8 +958,9 @@ function field_collection_field_update($entity_type, $entity, $field, $instance,
-  if ($ids = field_collection_field_item_to_ids($items)) {
+  if ($ids && field_info_field($field['field_name'])) {
     // We filter out entities that are still being referenced by other
     // host-entities. This should never be the case, but it might happened e.g.
     // when modules cloned a node without knowing about field-collection.

Should exclude deleted collection fields. But introduces performance regression while #1040790: _field_info_collate_fields() memory usage not commited

likewhoa’s picture

Priority: Major » Normal
Status: Needs review » Reviewed & tested by the community

WFM thanks!

andypost’s picture

+1 to RTBC, no regression!

mo3.mo3’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta5

i get the same error. i see the patch in the previous post, how do i apply it?

andypost’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev
nasia123’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta5
Category: bug » task
Status: Reviewed & tested by the community » Fixed

I confirm that this works...

Deleted fields values however exist in the database (I checked field_config and field_config_instance tables) but now those fileds are not referenced, so the error is removed.

Maybe it should be mentioned somewhere in the fields_collection module , tha fields collection should be first removed one by one from the Fields Collections Structure Menu, before deleting a field collection from a content type... or maybe a field collection should not be allowed to be removed from a content type before deleting all items them first ...

klausi’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev
Category: task » bug
Status: Fixed » Reviewed & tested by the community

This has not been committed yet?

henrijs.seso’s picture

Fixes ugly bug. Thank you, klausi.

fago’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

I'm not sure how this can happen. Why should core invoke hook_field_delete() on a not more existing field? Sounds like a bug elsewhere to me.

Josh Benner’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

From what I can tell, when core "deletes" a field, it is still present waiting to be purged from the DB. When this occurs (field_purge_batch), field_purge_data() is called for the deleted field to get rid of any lingering data, which in turn explicitly invokes hook_field_delete(). I don't think this is a bug elsewhere.

The patch in #7 works for me.

haphvn’s picture

#7: fieldcol-1866032-7.patch queued for re-testing.

haphvn’s picture

that's nice
#7 it works for me
many thanks

roderik’s picture

RTBC +1.

I see what Josh Benner sees. hook_field_delete gets explicitly invoked by field_purge_data().
Also, when googling some, I found BulkDeleteTest for D8 -- the comments in the test imply that this is intended behavior.

@fago I'm nowhere near as qualified to judge this as you / don't know the code -- but would this be a core documentation issue, then? (It should be explicitly mentioned that hook_field_delete gets called for already deleted fields, to prevent future people from encountering this?)
Anyway, it seems Field Collection should be fixed as per this issue.

jherencia’s picture

Same problem here.

kscheirer’s picture

Same problem as described above. Here's a backtrace as requested in #2.

  • #0 EntityFieldQuery->addFieldCondition(Array (), field_content_section, value, 1, , , ) called at [/Users/karl/www/rtw/htdocs/includes/entity.inc:663]
  • #1 EntityFieldQuery->fieldCondition(field_content_section, value, 1) called at [/Users/karl/www/rtw/htdocs/sites/all/modules/contrib/field_collection/field_collection.module:973]
  • #2 field_collection_field_delete(node, stdClass Object ([nid] => 170,[vid] => 170,[type] => page,[field_content_section] => Array ([und] => Array ([0] => Array ([value] => 1,[revision_id] => 1),[1] => Array ([value] => 2,[revision_id] => 2)))), Array ([translatable] => 0,[entity_types] => Array (),[settings] => Array ([hide_blank_items] => 1,[path] => ),[storage] => Array ([type] => field_sql_storage,[settings] => Array (),[module] => field_sql_storage,[active] => 1,[details] => Array ([sql] => Array ([FIELD_LOAD_CURRENT] => Array ([field_deleted_data_12] => Array ([value] => field_content_section_value,[revision_id] => field_content_section_revision_id)),[FIELD_LOAD_REVISION] => Array ([field_deleted_revision_12] => Array ([value] => field_content_section_value,[revision_id] => field_content_section_revision_id))))),[foreign keys] => Array (),[indexes] => Array (),[id] => 12,[field_name] => field_content_section,[type] => field_collection,[module] => field_collection,[active] => 1,[locked] => 0,[cardinality] => -1,[deleted] => 1,[columns] => Array ([value] => Array ([type] => int,[not null] => ,[description] => The field collection item id.),[revision_id] => Array ([type] => int,[not null] => ,[description] => The field collection item revision id.)),[bundles] => Array ()), Array ([label] => Content Section,[widget] => Array ([weight] => 2,[type] => field_collection_embed,[module] => field_collection,[active] => 0,[settings] => Array ()),[settings] => Array ([user_register_form] => ),[display] => Array ([default] => Array ([label] => hidden,[type] => hidden,[weight] => 1,[settings] => Array ())),[required] => 0,[description] => ,[default_value] => ,[id] => 20,[field_id] => 12,[field_name] => field_content_section,[entity_type] => node,[bundle] => page,[deleted] => 1), und, Array ([0] => Array ([value] => 1,[revision_id] => 1),[1] => Array ([value] => 2,[revision_id] => 2)), , ) called at [/Users/karl/www/rtw/htdocs/modules/field/field.attach.inc:209]
  • #3 _field_invoke(delete, node, stdClass Object ([nid] => 170,[vid] => 170,[type] => page,[field_content_section] => Array ([und] => Array ([0] => Array ([value] => 1,[revision_id] => 1),[1] => Array ([value] => 2,[revision_id] => 2)))), , , Array ([field_id] => 12,[deleted] => 1)) called at [/Users/karl/www/rtw/htdocs/modules/field/field.crud.inc:927]
  • #4 field_purge_data(node, stdClass Object ([nid] => 170,[vid] => 170,[type] => page,[field_content_section] => Array ([und] => Array ([0] => Array ([value] => 1,[revision_id] => 1),[1] => Array ([value] => 2,[revision_id] => 2)))), Array ([translatable] => 0,[entity_types] => Array (),[settings] => Array ([hide_blank_items] => 1,[path] => ),[storage] => Array ([type] => field_sql_storage,[settings] => Array (),[module] => field_sql_storage,[active] => 1,[details] => Array ([sql] => Array ([FIELD_LOAD_CURRENT] => Array ([field_deleted_data_12] => Array ([value] => field_content_section_value,[revision_id] => field_content_section_revision_id)),[FIELD_LOAD_REVISION] => Array ([field_deleted_revision_12] => Array ([value] => field_content_section_value,[revision_id] => field_content_section_revision_id))))),[foreign keys] => Array (),[indexes] => Array (),[id] => 12,[field_name] => field_content_section,[type] => field_collection,[module] => field_collection,[active] => 1,[locked] => 0,[cardinality] => -1,[deleted] => 1,[columns] => Array ([value] => Array ([type] => int,[not null] => ,[description] => The field collection item id.),[revision_id] => Array ([type] => int,[not null] => ,[description] => The field collection item revision id.)),[bundles] => Array ()), Array ([label] => Content Section,[widget] => Array ([weight] => 2,[type] => field_collection_embed,[module] => field_collection,[active] => 0,[settings] => Array ()),[settings] => Array ([user_register_form] => ),[display] => Array ([default] => Array ([label] => hidden,[type] => hidden,[weight] => 1,[settings] => Array ())),[required] => 0,[description] => ,[default_value] => ,[id] => 20,[field_id] => 12,[field_name] => field_content_section,[entity_type] => node,[bundle] => page,[deleted] => 1)) called at [/Users/karl/www/rtw/htdocs/modules/field/field.crud.inc:887]
  • #5 field_purge_batch(10) called at [/Users/karl/www/rtw/htdocs/modules/field/field.module:342]
  • #6 field_cron()
  • #7 call_user_func_array(field_cron, Array ()) called at [/Users/karl/www/rtw/htdocs/includes/module.inc:833]
  • #8 module_invoke(field, cron) called at [/Users/karl/www/rtw/htdocs/includes/common.inc:5250]
  • #9 drupal_cron_run() called at [/Users/karl/www/drush/commands/core/core.drush.inc:667]
  • #10 drush_core_cron()
  • #11 call_user_func_array(drush_core_cron, Array ()) called at [/Users/karl/www/drush/includes/command.inc:352]
  • #12 _drush_invoke_hooks(Array ([description] => Run all cron hooks in all active modules for specified site.,[aliases] => Array ([0] => cron),[command] => core-cron,[command-hook] => core-cron,[bootstrap] => 6,[callback arguments] => Array (),[commandfile] => core,[path] => /Users/karl/www/drush/commands/core,[engines] => Array (),[callback] => drush_command,[sections] => Array ([examples] => Examples,[arguments] => Arguments,[options] => Options),[arguments] => Array (),[required-arguments] => ,[options] => Array (),[sub-options] => Array (),[allow-additional-options] => ,[examples] => Array (),[core] => Array (),[scope] => site,[drupal dependencies] => Array (),[drush dependencies] => Array (),[handle-remote-commands] => ,[strict-option-handling] => ,[bootstrap_errors] => Array (),[topics] => Array (),[hidden] => ,[is_alias] => 1,[argument-description] => Array ()), Array ()) called at [/Users/karl/www/drush/includes/command.inc:214]
  • #13 drush_command()
  • #14 call_user_func_array(drush_command, Array ()) called at [/Users/karl/www/drush/includes/command.inc:182]
  • #15 drush_dispatch(Array ([description] => Run all cron hooks in all active modules for specified site.,[aliases] => Array ([0] => cron),[command] => core-cron,[command-hook] => core-cron,[bootstrap] => 6,[callback arguments] => Array (),[commandfile] => core,[path] => /Users/karl/www/drush/commands/core,[engines] => Array (),[callback] => drush_command,[sections] => Array ([examples] => Examples,[arguments] => Arguments,[options] => Options),[arguments] => Array (),[required-arguments] => ,[options] => Array (),[sub-options] => Array (),[allow-additional-options] => ,[examples] => Array (),[core] => Array (),[scope] => site,[drupal dependencies] => Array (),[drush dependencies] => Array (),[handle-remote-commands] => ,[strict-option-handling] => ,[bootstrap_errors] => Array (),[topics] => Array (),[hidden] => ,[is_alias] => 1,[argument-description] => Array ())) called at [/Users/karl/www/drush/drush.php:92]
  • #16 _drush_bootstrap_and_dispatch() called at [/Users/karl/www/drush/drush.php:61]
  • #17 drush_main() called at [/Users/karl/www/drush/drush.php:16]

Patch in #7 fixed the problem for me. Using 7.x-1.0-beta5.

jschrab’s picture

I also have found that the patch in #7 helps. But even if one clears out child fields before deleting a field collection, tables "field_collection_item" and "field_collection_item_revision" may still have references in them that, in the best of all worlds, should be cleared out too - maybe this patch needs work?

Finally, having cron run so that fields marked for deletion DO get deleted is something to be expected to TOTALLY clear this up #1400478: Cannot disable module - required by Drupal, fields pending deletion

AFAIK :)

fago’s picture

#7: fieldcol-1866032-7.patch queued for re-testing.

fago’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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

hollyfox’s picture

Issue summary: View changes

Just for anyone coming into this for the same problem. This issue can also result when you delete a field that is tied to another node referrer in another content type via corresponding node references. *Even if the patch above is installed. I was able to fix it by deleting the compliment node referrer field in the other content type.

I added this to the corresponding node references project issue queue just so there is no confusion. https://www.drupal.org/node/2663548

marleo’s picture

Also for searchers: despite the patch in #7 apparently being committed about 4 years ago, it still hasn't made its way into the stable release, so you'll need to apply it manually. For 7.x-1.0-beta12, you're looking around line 630 of field_collection.module. And it does fix the problem.

berenddeboer’s picture

Thanks @marleo! I was getting exactly the same error, just applying the patch worked. This bug has not been fixed.

kscheirer’s picture

Comments on a closed ticket are unlikely to get much attention. I'd suggest opening a new issue.

joegraduate’s picture

I created a new issue regarding the absence of the fix for this issue in recent releases here: #3029628: Re-apply fix from #1866032 (EntityFieldQueryException: Unknown field)

aswathyajish’s picture

#7 worked for me. Thanks a lot.