Summary

Need to prevent the creation of entity types named with certain words (see #23). These words can be related to core and other existing entities entities, existing table names in general, protected database table names, and possibly other factors. With potential conflicts coming from so many different sources, namespacing (as suggested in #2, #4, and #19) is going to be the only sustainable solution.

This is currently the only blocker for a 7.x-2.0 release.

Looking to implement a configurable namespacing prefix, similar to how "field_" prefixes field machine names but can be configured globally.

Will need to test to make sure that existing entity types are not affected by this change - thinking about entity CRUD functions and templates/theming.

Original issue reported by @webmasterslava

I have created new entity type with machine name "category" through ECK UI, then created first entity with this entity type through ECK UI, after that I see the following error on entities overview page "admin/structure/eck/category/category":

Warning: Missing argument 2 for user_category_load() in user_category_load() (line 1914 of modules/user/user.module).
Warning: Missing argument 3 for user_category_load() in user_category_load() (line 1914 of modules/user/user.module).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of includes/entity.inc).
Recoverable fatal error. Object of class EckEntity could not be converted to string in DatabaseStatementBase->execute() (line 2135 of includes/database/database.inc).

The same error I see when I'm trying to edit or delete this entity or delete entity type. So I can delete it only manually in database at "eck_category" table.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fmizzell’s picture

Status: Active » Closed (won't fix)

Wow, I found this very amusing, so I had to go dig in to see what is going on, and I found the culprit code:

foreach (module_implements($this->entityInfo['load hook']) as $module) {
  call_user_func_array($module . '_' . $this->entityInfo['load hook'], $args);
}

This is called in the Entity API's attachLoad method of the entity.controller class. So, there really isn't anything that ECK or Entity API can do, unless the whole community decides to change this naming convention for the entities hooks, it is just unfortunate that the user module happens to have a function called user_category_load().

acrazyanimal’s picture

Ha! I had a similar problem when I created an entity type called user_profile .... you can see how this could possibly go wrong. I don't think there is a way to check for this kind of thing, but perhaps by default we could add a prefix to machine names. Also I've added this note on Entity naming conventions to the documentation for ECK. Hopefully this can help others avoid this issue in the future.

Chris Gillis’s picture

Version: 7.x-1.1-alpha3 » 7.x-2.0-alpha1
Assigned: webmasterslava » Unassigned
Category: bug » feature
Status: Closed (won't fix) » Active

I just had a similar error when creating an entity named "role".

Recoverable fatal error: Object of class Entity could not be converted to string in DatabaseStatementBase->execute() (line 2139 of /Applications/MAMP/htdocs/test/includes/database/database.inc).

Is there a way to add the word "role" to a list of banned names and then display a more human-friendly error? It seems like this should not be too hard so I'm reopening this ticket.

acrazyanimal’s picture

That is a good question Chris, but the problem with that would be that any such banned list would constantly have to be updated and all conflicts would need to be found. I think it would be much simpler if we just automatically added the prefix 'eck_' to all entity machine names. This would pretty much avoid most if not all of these conflicts.

zacho’s picture

I recently created an entity type called "item" and upon adding one or trying to view the entity list:

Recoverable fatal error: Object of class Entity could not be converted to string in DatabaseStatementBase->execute() (line 2139 of /home/user/public_html/d7/includes/database/database.inc).

[Delete Dumb Question here]

gwynnebaer’s picture

Seems either modules would need to stop using the "_load" since it's now part of entity (certainly for D8), Entity API needs to rename. The code below, packaged into a validation on the entity name, will prevent a collision from being created, but only for one that already exists. It cannot handle the case of a module being added later that has the same name, so it's really not a true fix.

    $entity = 'role';
    $collision = 0;
    foreach (module_list(TRUE, $bootstrap) as $module) {
      if(function_exists($module.'_'.$entity.'_load')) {
        // That entity name is reserved.
        print "Entity name collision: ${module}_${entity}_load\n";
        $collision++;
      }
    }
    if(!$collision) {
      // The entity name is safe to use.
      print "Entity name: $entity is safe to use.\n";
    }

I vote for changing Entity API; hard but the right thing to do.

mihai_brb’s picture

I think it's the same for naming your entity "type".

DamienMcKenna’s picture

Title: Incompatibility entity type with machine name "category" » Protect against ECK names that will cause system errors
Version: 7.x-2.0-alpha1 » 7.x-2.x-dev
Issue summary: View changes

The module should be able to identify names that will cause conflicts.

tregismoreira’s picture

Same here. I've created an entity called Block (machine name "block"). So, when I tried to display the entity or delete it, I've got the same error.

johnlaine’s picture

I think that I am having the same issue with the name "task". Everything seems to work fine until I try to delete an entity, then I get an error

Recoverable fatal error: Object of class Entity could not be converted to string in DatabaseStatementBase->execute()
fmizzell’s picture

The problematic entity type name "region" was reported over there #2085187: Entity name conflicts with Drupal Hook names which breaks the site

corentin.crouvisier’s picture

I created an eck entity in relation with a node ( 2 entity references synchronized bidirectionally with my own code).
I added after a relation with the cer module and I have now the same error:
Recoverable fatal error: Object of class Entity could not be converted to string in DatabaseStatementBase->execute() (line 2171 of /includes/database/database.inc).
Disable my cer sync solve the problem, but I have a doubt about the compatibility of the two modules (or 3 modules if entity reference is a part of the problem when synchronizing entity references from eck via cer).

Note: problem only appears on eck entity creation, not editing.

Chris Gillis’s picture

corentin.crouvisier - I would suggest creating a separate ticket for that. If you think it is related to this issue, you can link to it, and let us know what your eck entity is named.

corentin.crouvisier’s picture

You are right, it's not an issue relative to the entity name, I move it to this cer issue cer+eck+entity reference fields : fatal error creating entity contents, but I think the fatal error caused by an entity object sended as argument could have a similar explaination with #10 and could be associated.

pianomansam’s picture

Title: Protect against ECK names that will cause system errors » Protect against reserved entity type names

I'm going to update the title of this issue to focus it just on entity type names. I'll create separate issues for reserved properties, bundles, and fields if they don't already exist.

pianomansam’s picture

I found two more reserved entity type names: button and link.

marco.b’s picture

Priority: Normal » Major

I ran into this issue by creating eck bundle 'item' before I read that (#5) and earned the error:

    Warning: array_flip(): Can only flip STRING and INTEGER values! in EntityAPIController->load() (Zeile 219 von /is/htdocs/…/sites/all/modules/entity/includes/entity.controller.inc).
    Recoverable fatal error: Object of class Entity could not be converted to string in DatabaseStatementBase->execute() (Zeile 2171 von /is/htdocs/…/includes/database/database.inc).

Set Priority to Major because after that I couldn't delete the bundle anymore at sidebuilder level. Even uninstalling ECK isn't possible through backend.

I suggest ECK should have something like a namespace blacklist.

marco.b’s picture

Category: Feature request » Bug report

Changed this one to bug report, for reasons see #17.

C-Logemann’s picture

Component: User interface » Code
Priority: Major » Critical

As a Module to provide entity configurations for site builders this is really a bug in code. And if there can be situations where you can't revert a "bad" entity name it's a critical issue in my opinion.

I think a blacklist as suggested in #17 by would be easy to realize. But what about a default namespace prefix "eck_" to avoid any conflicts with other modules?

marco.b’s picture

same with eck bundle 'role' (that was predictable).

akalata’s picture

I usually namespace, this time I didn't. Type name "group" MySQL/MariaDB really doesn't like that....

I think we do need to make an effort to protect against these errors, since there is no way to recover (on D8, I can't uninstall just using drush).

kpv’s picture

Issue tags: +needs port to Drupal 8

same for drupal 8
entity type with machine name 'config' breaks entities overview page and makes ECK mostly unusable

akalata’s picture

Issue summary: View changes

So far reported in this issue:

  • category
  • user_profile
  • region
  • role
  • item
  • type
  • block
  • task
  • button
  • link
  • group
  • config

Updating issue summary with the goal for namespacing; if there are users that don't like the forced namespacing, they can still create their entities programatically.

Though I guess we don't need to force a specific namespace; it can default to "eck_" but could otherwise be a text string, similar to the the way "field_" can be configured.

Kristen Pol’s picture

Priority: Critical » Normal

Downgrading to Normal since this issue is 7 years old and users are using ECK ok. Documentation (to not use existing names) can help with this right now.

BassPlaya’s picture

I believe I had a similar issue when using the machine name "transaction" when using Drupal Commerce module.
I had a very similar experience like mentioned above:

Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 175 of /Users/GraphicDesign/Sites/www.tetd7prodcopy.devel/includes/entity.inc).
Recoverable fatal error: Object of class Entity could not be converted to string in DatabaseStatementBase->execute() (line 2227 of /Users/GraphicDesign/Sites/www.tetd7prodcopy.devel/includes/database/database.inc).

My solution was to create a quick module to debug i.e. print all entities on the site and then do a search for which entity you seem to have a problem with. What I found was "transaction_id" used by Drupal Commerce and I believe that's the reason for the error.
I got the idea from this link: How can I find all Entity Types in a site.

put that in a simple module, enable it and find the culprit.

<?php
function davido_debugs_form_alter(&$form, &$form_state, $form_id) {
      debug(entity_get_info());
}

See screenshots.