I deleted the "Dimensions" field from my product type and got this set of errors:

    Notice: Undefined property: stdClass::$commerce_price in commerce_tax_field_attach_load() (line 467 of /home/rfay/workspace/commerce/sites/all/modules/commerce/modules/tax/commerce_tax.module).
    Warning: Invalid argument supplied for foreach() in commerce_tax_field_attach_load() (line 467 of /home/rfay/workspace/commerce/sites/all/modules/commerce/modules/tax/commerce_tax.module).
    Notice: Undefined property: stdClass::$commerce_price in commerce_tax_field_attach_load() (line 467 of /home/rfay/workspace/commerce/sites/all/modules/commerce/modules/tax/commerce_tax.module).
    Warning: Invalid argument supplied for foreach() in commerce_tax_field_attach_load() (line 467 of /home/rfay/workspace/commerce/sites/all/modules/commerce/modules/tax/commerce_tax.module).
    Notice: Undefined property: stdClass::$commerce_price in commerce_tax_field_attach_load() (line 467 of /home/rfay/workspace/commerce/sites/all/modules/commerce/modules/tax/commerce_tax.module).
    Warning: Invalid argument supplied for foreach() in commerce_tax_field_attach_load() (line 467 of /home/rfay/workspace/commerce/sites/all/modules/commerce/modules/tax/commerce_tax.module).
CommentFileSizeAuthor
#6 1356958-7.patch730 bytesvasike

Comments

rszrama’s picture

Not sure what the best solution here will be. The problem appears to be that deleting a field isn't clearing the field info cache early enough, and deleting the field appears to trigger hook_field_attach_load() for some reason. I'm curious to know exactly why that's happening - does Drupal really go through and load every single entity containing a deleted field to remove the old data? If so, is there some secret batch here I don't know about?

recrit’s picture

field_ui.admin.inc line 1742 calls field_purge_batch() to purge fields with minimal or no field data. The function field_purge_batch() only sends a stub entity (as returned from EntityFieldQuery) to field_attach_load(). So commerce_tax_field_attach_load() is called and loops through all defined fields on the product; however, these fields will not exist on this stub entity sent from field_purge_batch().

stan turyn’s picture

subscribing

vasike’s picture

Status: Active » Needs work

i can confirm this error message.
an easy and quick solution to avoid this error will be to add a check for this the "Notice: Undefined property" right before ethe line pointed by the error message.

     if ($field['type'] == 'commerce_price' && isset($product->{$field_name})) {

instead of

     if ($field['type'] == 'commerce_price') {
rfay’s picture

Status: Needs work » Active

@vasike please provide a patch. Stays in "active" until there's a patch.

vasike’s picture

Status: Active » Needs review
StatusFileSize
new730 bytes

ok. here is the patch.

rszrama’s picture

Status: Needs review » Fixed

Cool, that did it. Very poor form for Drupal to be functioning this way, but I'm not sure what ya can do. If a hook docblock and parameter name indicates it gets an entity (or set of entities), then it should always do just that. C'est la vie... I've simply put a comment on http://api.drupal.org/api/drupal/modules--field--field.api.php/function/... for now documenting this behavior. Not sure if this should be pushed upstream to Drupal core or not. Anyone else think so?

Committed #6, though I changed it to !empty() instead of !isset().

Status: Fixed » Closed (fixed)

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