Problem/Motivation

So in field_update_field it attempts to determine if the field has data and then passes that into hook_field_update_forbid so that modules can prevent field schema changes if a field has data and schema changes are an issue for them.

field_update_field checks to see if the updated field has data, though not the existing field.
This is a subtle difference, and with the default sql storage engine, means that the EFQ executes just fine, as the DB table has exactly the same name, but if one has a storage engine where say fields are stored in differently named tables for different schema column settings, then the EFQ will attempt to search in the wrong table.

Proposed resolution

Instead of passing do this:

$has_data = field_has_data($field);

We can do this:

$has_data = field_has_data($prior_field);

Remaining tasks

Review the test, and the patch.

User interface changes

None.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Steven Jones’s picture

Status: Active » Needs review
Related issues: +#2261099: File the core issue
FileSize
505 bytes

Here's a patch to fix the issue, lets see if anything depends on the broken behavior.

Steven Jones’s picture

Issue summary: View changes

To be clear about what's going on here:

field_has_data constructs an EFQ and then runs it to determine if the field has data, but the field data it is passed is for the new field, not the existing field.
If the field storage engine cares, and does something like query a different table, then the wrong table will be queried by the EFQ.

Steven Jones’s picture

Here's a patch that just has the test.

Status: Needs review » Needs work
Steven Jones’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.68 KB

And here's a patch that includes the test and fix.

Steven Jones’s picture

Status: Needs review » Needs work

The last submitted patch, 5: drupal-2261519-field_update_field-wrong-field-checked.patch, failed testing.

Steven Jones’s picture

Incorrect patches above. That'll teach me to do the work in one codebase and then copy/paste to another.

Here's the patch without the fix.

Steven Jones’s picture

And then with the fix.

Steven Jones’s picture

Status: Needs work » Needs review
Steven Jones’s picture

Issue summary: View changes
Status: Needs review » Needs work

Gah, this test clearly isn't working, the one in #8 should have failed.

Steven Jones’s picture

Right, let's try that again eh, with all the bits of code that need to be there to make the test work.

So basically the point of the test is to set it up so that if someone uses the 'new' field settings to do an EFQ, then we get an exception.

Steven Jones’s picture