Introduced in #361683: Field API initial patch and wasn't even questioned once in the entire issue.

Field data tables contain references to the entity type, entity bundle, and entity ID. The entity type is not stored as entity_type, but as etid:

    'description' => "Data storage for field {$field['id']} ({$field['field_name']})",
    'fields' => array(
      'etid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The entity type id this data is attached to',
      ),

What is the purpose of the etid abstraction?

It is "resolved" through the following table:

  $schema['field_config_entity_type'] = array(
    'fields' => array(
      'etid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The unique id for this entity type',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'description' => 'An entity type',
      ),
    ),
    'primary key' => array('etid'),
    'unique keys' => array('type' => array('type')),
  );

There is a unique index on the type column, so etid is nothing else than type as integer.

Abstraction for the sake of abstraction?

But wait... - it gets better!

/**
 * Retrieve or assign an entity type id for an entity type.
 *
 * @param $entity_type
 *   The entity type, such as 'node' or 'user'.
 * @return
 *   The entity type id.
 *
 */
function _field_sql_storage_etid($entity_type) {
  $etid = variable_get('field_sql_storage_' . $entity_type . '_etid', NULL);
  if (!isset($etid)) {
    $etid = db_insert('field_config_entity_type')->fields(array('type' => $entity_type))->execute();
    variable_set('field_sql_storage_' . $entity_type . '_etid', $etid);
  }
  return $etid;
}

So...

  1. Instead of having entity_type directly available in the field data tables...
  2. everyone needs to lookup what etid means in {field_config_entity_type}...
  3. whereas the entire table contents of {field_config_entity_type} are duplicated into system variables...
  4. and only field_sql_storage module contains a private helper function to resolve the mapping...
  5. even though this table actually belongs to field.module.

WTF?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Now that's... unpleasant.

sun’s picture

Not to mention that this is a *HUGE* bottleneck for Views...

bojanz’s picture

With RC1 out, how much of it can we kill? Technically, these are internal implementation details, nothing user-facing (if we disregard Views, which would benefit with this changing anyway...)

Stil waiting to see if anyone has an explanation why this is good, the Field API group brainstormed on a lot of details that I'm not familiar with.

yched’s picture

There is absolutely no good reason for this. Definite WTF.
Unfortunately, by the time this fact was established, we were already in 'no schema change' freeze.

Damien Tournoud’s picture

Yes, we discussed changing that a few times already (including in Vienna while porting Views to the Field API...), but simply failed to actually do it.

I don't believe it is actually a bottleneck for Views.

catch’s picture

I can't stand this but while I have worked on Field API a fair bit, I've never had to directly deal with the etid stuff, so was never motivated to look at it. I've not seen anyone else really mention it until sun opened this issue, which suggests if we killed it, no-one is going to notice.

Also:

function _field_sql_storage_etid($entity_type) {
  $etid = variable_get('field_sql_storage_' . $entity_type . '_etid', NULL);
  if (!isset($etid)) {
    $etid = db_insert('field_config_entity_type')->fields(array('type' => $entity_type))->execute();
    variable_set('field_sql_storage_' . $entity_type . '_etid', $etid);
  }
  return $etid;
}

Is this 'caching'? If it is, let's either remove it or have it be a cache_get().

sun’s picture

Problem space being that the http://drupal.org/project/relation project makes advanced usage of field data tables.

With current HEAD, there's no simple way to figure out the mappings as well as reverse mappings (etid -> type) without a direct database query and additional massaging:

  $type_id = db_query('SELECT type, etid FROM {field_config_entity_type}')->fetchAllKeyed();
  $id_type = array_flip($type_id);

So at the very least (if we can't do the proper fix of changing etid to entity_type),

1) there should be a proper API function to retrieve the mappings.

2) the mappings should be properly cached (instead of system variables).

3) the functionality belongs to Field API, not Field SQL Storage module.

catch’s picture

If we have to have etid, what about adding it to entity_info()? That would be both cached, and an api function.

yched’s picture

I guess field.module could add the etid in field_entity_info_alter().
That's taking a sad but relatively self-contained-in-field_sql_storage WTF, and promoting it to the entity API though...

@sun : relation.module directly hits field_sql_storage table ??

sun’s picture

Status: Active » Needs review
FileSize
3.02 KB

Something along of these lines...

sun’s picture

FileSize
3.07 KB
bojanz’s picture

Well, that makes things less ugly.
Nice cleanup, sun!

Is there any chance we could address:

4. and only field_sql_storage module contains a private helper function to resolve the mapping...

Can't see that change hurting anyone...

yched’s picture

Status: Needs review » Reviewed & tested by the community

Sure, thanks sun ! patch #11 is a nice no-brainer. RTBC if the bot comes green

re #12 : Only field_sql_storage uses that ugly construct. I see no need to promote it outside of field_sql_storage ?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, drupal.etid_.11.patch, failed testing.

bojanz’s picture

@yched
Okay, then. Makes sense (I was only responding to sun's initial list of problems from the original post)

yched’s picture

Attached patch fixes failures in "Field SQL storage tests" and "ExpandNode entity query alter" test classes, caused by leftover variable_get('field_sql_storage_[TYPE]_etid') calls in FieldSqlStorageTestCase::testEntityTypeId() and _node_query_node_access_alter().

The fail in "Comment interface" looks like it is caused by the static used in _field_sql_storage_etid(), not being refreshed on the client side while being outdated on the tested side. Your typical fun with tests and statics. The test passes if I remove the drupal_static() call.

I did not fix that last fail, stopped there for tonight. There should be one fail left, but I'll let the bot confirm.

yched’s picture

Status: Needs work » Needs review

The _node_query_node_access_alter() bit mentioned above worries me a lot. I didn't realize etids had spilled in node access query rewriting.

field_sql_storage_field_storage_query() adds a 'entity_field_access' tag to the entityQueries.
This triggers _node_query_node_access_alter(), which in turn has code which relies on field_sql_storage's etids, even though field_sql_query might not be the storage engine in use (the module itself is required, though, so etids are at least always available). This means that a module that wants to provide alternate SQL storage *has* to use field_sql_storage's sick etid construct if it wants to trigger node_access checks.

At what point do we decide that this is silly and we're better off altering the schema to get rid of {field_config_entity_type}, and store string entity_type names in our field data tables ?
I hardly see how this would affect anything else than Views, and my bet is they would be more than happy with the change.

Status: Needs review » Needs work

The last submitted patch, field_etid-986992-16.patch, failed testing.

sun’s picture

Priority: Normal » Major

#17 really sounds worrying. I'd be totally in favor of properly fixing etid to become entity_type; i.e., removing this entire insane construct.

Based on the discussion here, the schema change only seems to affect fields using field_sql_storage and no other storage engines.

Dave Reid’s picture

Oh good lord this is major WTF. I've been wondering for a long time why we've even needed etids.

yched’s picture

yched’s picture

Status: Needs work » Needs review
FileSize
38.94 KB

Attached patch removes the field_config_entity_type table, and stores an 'entity_type' string instead of an 'etid' int in the field data tables. Upgrade path included.

Note : around 1/3 of the patch is updating sample hooks copied straight from field_sql_storage in field.api.php (eww).
The actual changes are relatively straightforward.

yched’s picture

Fix comment typo.

KarenS’s picture

I vaguely remember something about using the numeric etid instead of the string entity type name to speed up performance or improve indexing or something like that in the field tables. In case that bit of history helps or changes anything.

I have code that will probably have to be rewritten but I am not at all opposed to making this change.

yched’s picture

@KarenS : Exactly. The etid indirection was introduced under the assumption that running JOINs or WHEREs on an int column would be faster than on a string.
According to DamZ, this is useless to begin with, as db engines already perform such an optimization internally on indexed string columns having a small number of distinct values - which exactly maps the case of the 'entity_type' column in field data tables.

So, big WTF for no gain :-). But this spills over to Views (the generated query can be different on dev site and on production site because etids can be different), and, as #17 shows, to any other field storage backend that might want to store fields in SQL.

chx’s picture

Status: Needs review » Reviewed & tested by the community

I can haz simplification pliz?

carlos8f’s picture

Nice beefy 38k patch. Hopefully the test coverage is good enough so that we don't have regressions here :)

dawehner’s picture

This patch simplifies the views code a bit.

Additional as sun explained in irc the join will not be slower.

Dries’s picture

I'll commit this patch, but I'd love to have @sun sign off on the latest patch.

sun’s picture

Issue tags: +API change
FileSize
39.36 KB

This patch is the "proper fix" and exactly what we want and need to do. Thanks, yched, for taking on the challenge!

Originally, I didn't expect that we'd be able to do the proper fix, especially after a quick inspection of where and how the etid mapping is currently used throughout core. However, upon learning that it is also involved in _node_query_node_access_alter(), and that replacing etid with entity_type columns only affects field data tables of field_sql_storage.module, we are now confident that the change is both simple enough and important enough to do.

Truth to be told, there's a small API change here. Even though various people already stated that they never ever had to deal with etids, even after intensively working with fields, this patch still removes the entire field_config_entity_type table (by field_sql_storage.module), the individual system variables per entity type containing the etid values, and lastly the private helper function from field_sql_storage.module that returns etid values and dynamically creates new system variables.

However, this API change should only affect highly advanced modules, which are directly performing queries on field data tables. From those, at least Date module and Views are affected, but both maintainers already stated that they would be more than happy about this change, as it also allows to simplify their code.

+++ modules/field/modules/field_sql_storage/field_sql_storage.install
@@ -122,5 +101,83 @@ function field_sql_storage_update_7000() {
+      db_add_field($table, 'entity_type', $column, $indexes);

The $indexes variable is not defined. Seems to be a stale leftover from a previous approach, as indexes are properly handled separately in the code now, right after the addition of the column.

Removed that in attached patch. No other changes, so leaving RTBC.

Powered by Dreditor.

yched’s picture

re $indexes : right, leftover from a previous version where the indexes were added along with the column. #30 is correct , thanks !

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Great. Thanks for this important. Committed to CVS HEAD.

rfay’s picture

Breathtaking. I think this probably needs to be announced, with basically the description in #30.

chx’s picture

If you announce this then also announce that if you are affected by this then it's very , very likely you are doing it wrong.

andypost’s picture

Docs page needs to be fixed at http://drupal.org/node/890070

yched’s picture

rfay’s picture

Priority: Major » Critical
Status: Fixed » Needs work

I pulled and ran update.php today and got these results:

The following updates returned messages
field_sql_storage module
Update #7001

    * Failed: DatabaseSchemaObjectExistsException: Cannot add field <em class="placeholder">field_deleted_revision_11</em>.<em class="placeholder">entity_type</em>: field already exists. in DatabaseSchema_mysql->addField() (line 324 of /home/rfay/workspace/d7git/includes/database/mysql/schema.inc).

After the failed update, visiting /node gets this result:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_type' in 'where clause': SELECT t.* FROM {field_data_field_i2} t WHERE (entity_type = :db_condition_placeholder_0) AND (entity_id IN (:db_condition_placeholder_1, :db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4)) AND (language IN (:db_condition_placeholder_5)) AND (deleted = :db_condition_placeholder_6) ORDER BY delta ASC; Array ( [:db_condition_placeholder_0] => node [:db_condition_placeholder_1] => 206 [:db_condition_placeholder_2] => 208 [:db_condition_placeholder_3] => 209 [:db_condition_placeholder_4] => 210 [:db_condition_placeholder_5] => und [:db_condition_placeholder_6] => 0 ) in field_sql_storage_field_storage_load() (line 326 of /home/rfay/workspace/d7git/modules/field/modules/field_sql_storage/field_sql_storage.module).

It's possible that this is related only to my local and something about its history, in which case this can be demoted from critical. I'll try to recreate it. I unfortunately did not make a backup of my db before updating.

bojanz’s picture

Related views issue: #998666: Adding FieldAPI fields causes "Column not found" errors, expecting an "entity type" field
On the other hand, I updated two old dev setups without a problem...

int’s picture

@rfay, maybe you pressed two times simultaneos(double click) in the upgrade button, and execute two times the upgrade? or this don't work like that?

this patch worked fine for my site.

sun’s picture

Priority: Critical » Major

I also updated without any errors.

However, I need to test again, since field_deleted_revision_11 indicates that rfay had a to be deleted field (table).

rfay’s picture

I'm working on trying to recreate. I did find a dump of my local from a couple of weeks ago.

Reverting the code to right before this commit and updating the db and then trying to add a field to a content type I get this right when trying to add the field:

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'd7git.field_config_entity_type' doesn't exist: INSERT INTO {field_config_entity_type} (type) VALUES (:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => node ) in _field_sql_storage_etid() (line 110 of /home/rfay/workspace/d7git/modules/field/modules/field_sql_storage/field_sql_storage.module).

I'll see if I can get a clear result on this.

sun’s picture

@rfay: That error means that you db dump does not contain the field_config_entity_type table, or, that you did not really reverted your code base to a date at which the field_sql_storage module update did not exist yet (so that table was deleted upon running update.php).

rfay’s picture

Status: Needs work » Fixed

I am able to recreate this #fail with this sequence of events.

1. Update the code to latest
2. Create a new multivalue file field on the article content type
3. Then run updatedb.

Since this is not an acceptable upgrade scenario (work done after code changed but before updatedb) I'm going to put this back to fixed. If there are appropriate scenarios in which it happens we can reopen.

yched’s picture

Status: Fixed » Needs work

The error message in #37 does seem to indicate that either :
a) the update was run twice
b) for some reason, the field_deleted_revision_11 table was added twice in the list of tables to process
at the beginning of field_sql_storage_update_7001()

I hardly see how b) could happen, but this could possibly be prevented by keying the $sandbox['tables'] array :

       $sandbox['tables']["field_deleted_data_{$field['id']}"] = "field_deleted_data_{$field['id']}";
       $sandbox['tables']["field_deleted_revision_{$field['id']}"] = "field_deleted_revision_{$field['id']}";

Not where I can roll a patch, unfortunately...

yched’s picture

Status: Needs work » Fixed

crosspost :-)

yched’s picture

Title: Insane etid / {field_config_entity_type} abstraction » Insane etid / {field_config_entity_type} abstraction (friendlier upgrade function)
Priority: Major » Normal
Status: Fixed » Needs review
FileSize
635 bytes

I guess we *could* meet nasty edge cases producing this mix of 'old version' (etid) and 'new version' (entity_type) schemas for field data tables.

Example :
A few weeks/months from now, a d7-RC2 site gets wants to update to d7.2, and updates a couple contrib modules too. One of the updates, foo_update_7003() creates a field (foo can be core or contrib).
If foo_update_7003() runs before field_sql_storage_update_7001(), its field will be created using the new code, and thus directly with the 'new' schema. When field_sql_storage_update_7001() runs, it produces the errors mentioned in #37 when it tries to process the field table.
Predicting what happens in the future with updates and dynamically created tables has always been a fun sport with CCK :-)

In our case, it's easy to be more tolerant : only process a table if it still has an 'etid' column. Patch attached.

Anonymous’s picture

subscribing

chx’s picture

Status: Needs review » Reviewed & tested by the community

That's a good one.

Dave Reid’s picture

I also had a problem with this fix that was committed to core. My {field_revision_body} table has two revisions for node 2. The update drops the current primary key on etid, revision_id, deleted, delta, and language, and then attempts to add a primary key on the fields entity type, entity id, deleted, delta, and language, which are all the same for both revisions, and so I get SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry[error] 'node-2-0-0-und' for key 'PRIMARY' when running updatedb. Previously my revision tables do not have any primary key. So now I'm stuck with tables that have no primary key and have not had their etid columns removed.

yched’s picture

Crap. Correct, my bad. Will provide a fix tonight.

rfay’s picture

Status: Reviewed & tested by the community » Needs work
yched’s picture

So, the update functon that is currently in HEAD forgets that revision tables use different primary keys than 'current version' tables.
Fixing the current update function is easy, patch attached.

Working on a followup update func to fix dbs broken by the previous update :-(

Dave Reid’s picture

Status: Needs work » Needs review

Well the update failed for me, so we can fix it in the same update function. Looks good to me, but could use another tester.

yched’s picture

Dbs where the upgrade has failed are left in a state where some tables have been processed, some haven't, and one (the one where the upgrade failed) is left in between (no PK, both the old 'etid' and the new 'entity type' columns).

Here's a new version of field_sql_storage_update_7001() that accounts for all cases, by wrapping checks around each step (add the new column, create the PK, drop the old column). As Dave Reid points, 7001 will replay on dbs where it previously failed.

I tested this to work on a 'clean' pre-commit d7 db, and on a db where the current field_sql_storage_update_7001() broke in the middle.

Sorry for the trouble :-(

aidanlis’s picture

Latest patch works for me, thanks yched. The upgrade function from HEAD left me in table mismatch hell.

Berdir’s picture

Patch works for me on the side where I had the primary key error.

I have a different site where I got the following error:

Failed: DatabaseSchemaObjectExistsException: Cannot add field field_revision_field_properties.entity_type: field already exists. in DatabaseSchema_mysql->addField()

It looks like it tries to add the entity_type field again, this error already happened when i run the update the first time, without this patch.

sun’s picture

Status: Needs review » Needs work

We also need a new update to fix successfully updated revision tables -- 7001 only failed, when more than one revision exists per entity_id.

+++ modules/field/modules/field_sql_storage/field_sql_storage.install
@@ -151,12 +155,20 @@ function field_sql_storage_update_7001(&$sandbox) {
+      'data' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
+      'revision' => array('entity_type', 'revision_id', 'deleted', 'delta', 'language'),

I wonder whether the PK for revision tables shouldn't contain both entity_id and revision_id.

Only including revision_id means that we are presuming and expecting all revision IDs of any kind of entity to follow Node API's notion and behavior of revision IDs (unique vid "somewhat derived" from nid), whereas that's not really a natural pattern -- if I'd implement revisions from scratch in a new entity type today, then I'd rather go with simple 1,2,3,... revision IDs; they are still unique, because they apply to certain entity (ID) only.

Powered by Dreditor.

sun’s picture

Status: Needs work » Needs review
FileSize
3.46 KB

Incorporated #57.

yched’s picture

#57 / #58 make sense, but then _field_sql_storage_schema() needs to be adjusted for the new PK for revision tables.

re #56: it's not clear whether that "Cannot add field entity_type: already exists" error still happens with #54. It normally shouldn't, the column is only added if !db_field_exists($table, 'entity_type')

sun’s picture

@Berdir: Like @yched, I also think that with this new patch, the error you reported should no longer happen.

yched’s picture

#60 is good for me, although I can't RTBC myself.

Berdir’s picture

New error, don't ask me what the hell this is.. :)

Failed: DatabaseSchemaObjectDoesNotExistException: Cannot add field field_deleted_data_7.entity_type: table doesn't exist. in DatabaseSchema_mysql->addField()

No idea where field_deleted_data_7 is coming from. I deleted a field that was using a different storage_backend (mongodb) on that site, maybe that's confusing it..

yched’s picture

Wrapped both updates in if (db_table_exists($table))

sun’s picture

I think the problem rather is that we only want to update

    ->condition('storage_module', 'field_sql_storage')

;)

yched’s picture

Yup, agreed.

sun’s picture

Priority: Normal » Critical

Can anyone test this patch once more?

Bumping to critical, since

  1. existing D7 sites with actual revision data cannot update
  2. D7 sites not having multiple revisions stored were able to update to HEAD, but cannot store new revisions currently
sharikov’s picture

subscribing.

chx’s picture

Status: Needs review » Needs work

The comment "Revision tables of deleted fields are irrelevant, since no new data is written to them." would be much nicer if it would say "Revision tables of deleted fields do not need to be fixed here, since no new data is written to them."

Second, I do not understand what scenario got broken here. If it's the D6->D7 upgrade path then why is there no test? If it's not then why is this critical? If this is critical, then there must be a test for sure.

yched’s picture

The D6 -> D7 upgrade is not involved. field and field_sql_storage did not exist in D6, so field_sql_storage_update_X() are not played, and don't need to. Fields created during the upgrade are created with the correct schema straight ahead.

What was broken here is the D7 -> D7 upgrade. We currently don't test this, and I don't really see us adding tests for each new upgrade in the cycle ?

Berdir’s picture

The latest patch now runs through the update of my crazy site successfully :)

I agree that we don't need to add tests for a RC -> RC update. Instead, I think it is important that this is fixed ASAP, before more sites are messed up. My site with deleted mongod fields and revisions already is quite tricky to get right, we can always add another bugfix if yet another special case shows up.

sun’s picture

Status: Needs work » Needs review
FileSize
5.35 KB

Fixed that comment in 7001.

geerlingguy’s picture

Subscribe.

agentrickard’s picture

Noticed that revision saves failed on HEAD but not on RC2. This patch fixes that issue (which is item 2 in comment #66). +1.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Then let's go.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

sun’s picture

Status: Fixed » Needs review
FileSize
1.68 KB

Slept over this.

yched’s picture

@sun : it's not clear to me why we need this ?

sun’s picture

The underlying question is how fast a primary key change on a potentially large table is performed. If it's done in milliseconds, then this follow-up patch doesn't make sense to do. However, if it takes longer, then the idea is to skip the update 7002 for sites that already executed the (now fixed) update 7001. Because on those sites, update 7002 replaces the primary key with the identical primary key that 7001 already set.

moshe weitzman’s picture

IMO we shouldn't do performance optimizations on RC => RC sites. IMO we should go back to fixed.

webchick’s picture

Status: Needs review » Fixed

Agreed.

yched’s picture

Status: Fixed » Needs review

It's true that running 7002 is not needed if you ran the correct version of 7001 that is now in HEAD.

I'm a bit wary that we start to add those 'conditional update' considerations though.

carlos8f’s picture

Priority: Critical » Normal

Not critical anymore though.

yched’s picture

Title: Insane etid / {field_config_entity_type} abstraction (friendlier upgrade function) » Insane etid / {field_config_entity_type} abstraction
Priority: Normal » Major
Status: Needs review » Fixed

Sorry, crosspost. Back to 'fixed', as per webchick's #80.

+ Resetting original title and priority, for history's sake.

saintiss’s picture

Status: Fixed » Needs review

I ran into this error while upgrading my website from RC2 to RC3 and had to revert to a backup.

From what I read, this problem was supposedly fixed before RC3 came out, so what might explain this happening to me?

bojanz’s picture

Status: Needs review » Active

Which error did you actually get?

dawehner’s picture

In general Reverting a version isn't supported.

Please update to RC3 and fix the problem there.

saintiss’s picture

Tried to reproduce this...

So I upgrade from RC2 to RC3 after having disabled all non-core modules (mostly "media gallery" and prerequisites)

After the upgrade, before running update.php, trying to visit the site results in this:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_type' in 'where clause': SELECT t.* FROM {field_data_body} t WHERE (entity_type = :db_condition_placeholder_0) AND (entity_id IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) AND (language IN (:db_condition_placeholder_3)) AND (deleted = :db_condition_placeholder_4) ORDER BY delta ASC; Array ( [:db_condition_placeholder_0] => node [:db_condition_placeholder_1] => 2 [:db_condition_placeholder_2] => 20 [:db_condition_placeholder_3] => und [:db_condition_placeholder_4] => 0 ) in field_sql_storage_field_storage_load() (line 323 of /customers/ketelpatrouille.be/ketelpatrouille.be/httpd.www/modules/field/modules/field_sql_storage/field_sql_storage.module).

Then I run update.php:

field module

* 7001 - Fix fields definitions created during the d6 to d7 upgrade path.

field_sql_storage module

* 7001 - Remove the field_config_entity_type table and store 'entity_type' strings.
* 7002 - Fix primary keys in field revision data tables.

list module

* 7001 - Rename the list field types and change 'allowed_values' format.

It fails with the following error:

Failed: DatabaseSchemaObjectDoesNotExistException: Cannot add field field_deleted_data_6.entity_type: table doesn't exist. in DatabaseSchema_mysql->addField() (line 321 of /customers/ketelpatrouille.be/ketelpatrouille.be/httpd.www/includes/database/mysql/schema.inc).

running update.php again says:

field_sql_storage module

* 7001 - Remove the field_config_entity_type table and store 'entity_type' strings.
* 7002 - Fix primary keys in field revision data tables.

But it still fails with the same error. Visiting the site keeps showing the first error and the site remains broken...

saintiss’s picture

@dereine: by "reverting" I simply meant reinstating a DB backup.

What I am reporting here happens during an upgrade from RC2 to RC3, not during a reversion.

yched’s picture

Sigh. I guess there exists an awkward timeframe during field 'bulk deletion' ops where the sql storage table has been deleted while a 'field defnition' record still exists in {field_config}.

The update should just skip tables that do not exist...
Patch attached (just wraps a code block within if (db_table_exists($table)) {)

Affected sites have failed field_sql_storage_update_7001(), the fixed version will rerun on the next update.php.

saintiss’s picture

Status: Active » Needs review

If I interpret things correctly, this change has not made it in RC4. Is this because the status has not been set to "fixed" yet?

I am willing to test if someone could point me to a tarball which I can use to test?

yched’s picture

@saintiss ; the change itself is in RC3 and RC4 - it's only the followup patch in #89 that is still pending

saintiss’s picture

@yched: I tried RC3 and my problem was still present, hence my question...

webchick’s picture

saintiss: Can you test the patch in #89 and let us know if it works for you? Then this can get fixed before final release.

saintiss’s picture

@webchick: which tar.gz can I download that already includes the patch?

yched’s picture

@saintiss : the proposed fix is not available in any downloadable archive. You need to apply the patch attached in comment #89 above.

Read http://drupal.org/patch/apply for information. For a relatively simple patch like this one, you can also manually edit the field_sql_storage.install file in modules/field/modules/field_sql_storage/ to reproduce the changes.

saintiss’s picture

Tried it, and I can confirm that the patch works in combination with RC4

agentrickard’s picture

Status: Needs review » Reviewed & tested by the community

Marking #89 for commit.

sun’s picture

Yes, please.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Awesome! Thanks for your help in testing, saintiss!

Committed to HEAD. This fix will be available in Drupal 7.0. :)

Status: Fixed » Closed (fixed)

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