The Drupal 6-7 upgrade path does not attempt to preserve the description and required settings for node types. These are required fields by field API, so it leads to notices on node/n/edit as well as the loss of configuration data.

Sites that have already upgraded can work around this by saving the node type field settings again - which will fill in the default and remove the notices. We can't restore data for those sites though because it's already been destroyed on any site that upgraded.

The patch here adds those settings back if available, and adds some assertions to the existing node body upgrade test.

Original report:
Here's how I got the error:
1. clean d6.19 install
2. created a page (inserted title and body only)
3. upgraded to d7.x-dev (4 oct)
4. browsing to previous node edit page "/node/1/edit" gives the following error:

    *  Notice: Undefined index: description in field_multiple_value_form() (line 146 of /var/www/testsite//modules/field/field.form.inc).
    * Notice: Undefined index: required in field_multiple_value_form() (line 164 of /var/www/testsite/modules/field/field.form.inc).
    * Notice: Undefined index: required in field_multiple_value_form() (line 191 of /var/www/testsite/modules/field/field.form.inc).

running PHP Version 5.3.2-1ubuntu4.5

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ahwebd’s picture

Priority: Normal » Major

Same error on "create" pages ("node/add/page" and "/node/add/story")

ahwebd’s picture

Added new content type and the error does not show on create/edit pages for nodes of the new content type, it shows only on create/edit pages for nodes of upgraded content types

Berdir’s picture

The problem is http://api.drupal.org/api/function/node_update_7006/7, that needs to define description/required (and probably other things), similiar to http://api.drupal.org/api/function/system_update_7060/7

ahwebd’s picture

Yes you're right, and this concerns the "body" field instances, there is missing data that should be created for it in the node update function:

    // Add body field instances for existing node types.
    foreach ($node_types as $node_type) {
      if ($node_type->has_body) {
        $trim_length = variable_get('teaser_length_' . $node_type->type, $default_trim_length);

        $instance = array(
          'entity_type' => 'node',
          'bundle' => $node_type->type,
          'label' => $node_type->body_label,
          'widget' => array(
            'type' => 'text_textarea_with_summary',
            'settings' => array(
              'rows' => 20,
              'summary_rows' => 5,
            ),
            'weight' => -4,
            'module' => 'text',
          ),
          'settings' => array('display_summary' => TRUE),
          'display' => array(
            'default' => array(
              'label' => 'hidden',
              'type' => 'text_default',
            ),
            'teaser' => array(
              'label' => 'hidden',
              'type' => 'text_summary_or_trimmed',
              'trim_length' => $trim_length,
            ),
          ),
        );

we can see that "description" and "required" are missing in code above.

When creating new content type the body field instance is created with this code:

function field_ui_default_value_widget($field, $instance, &$form, &$form_state) {
  $field_name = $field['field_name'];

  $element = array(
    '#type' => 'fieldset',
    '#title' => t('Default value'),
    '#collapsible' => FALSE,
    '#tree' => TRUE,
    '#description' => t('The default value for this field, used when creating new content.'),
    // Make sure the values appear at the top-level of $form_state['values'].
    '#parents' => array(),
  );

  // Insert the widget.
  $items = $instance['default_value'];
  $instance['required'] = FALSE;
  $instance['description'] = '';
  // @todo Allow multiple values (requires more work on 'add more' JS handler).
  $element += field_default_form(NULL, NULL, $field, $instance, LANGUAGE_NONE, $items, $form, $form_state, 0);

  return $element;
}

(modules/field_ui/field_ui.admin.inc)

where we can see that "description" and "required" are present

To find missing items in instances of fields created by an update, I'm putting here two entries from database table `field_config_instance` , one created by an upgrade from d6 and the other newly created in d7

(5, 3, 'body', 'node', 'page', 'a:4:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:1:{s:15:"display_summary";b:1;}s:7:"display";a:2:{s:7:"default";a:2:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";}s:6:"teaser";a:3:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:11:"trim_length";i:600;}}}', 0),
(8, 3, 'body', 'node', 'test', 'a:7:{s:5:"label";s:4:"Body";s:11:"widget_type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"required";b:0;s:11:"description";s:0:"";}', 0);

we can see clearly that a number of items are missing on the upgraded one.

Don't know if this concerns other fields or only "body"

Note: the error disappears when: enabling module "field_ui", browsing to "manage fields" of content type and hitting "save'

KarenS’s picture

Title: after d6 > d7 upgrade: got error on node edit page » Node body 'description' and 'required' are missed on nodes upgraded from D6 to D7

Changing the title to be more descriptive.

tobiasb’s picture

Issue tags: +d7sc
FileSize
707 bytes
tobiasb’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, drupal_931512.patch, failed testing.

tobiasb’s picture

Status: Needs work » Needs review
FileSize
784 bytes
steinmb’s picture

I reported this dup #952970: Undefined index: required in field_default_form() and have tested the patch but it do not fix the problem. Still got the error message on both nodes with and without comments. The small patch do it's thing with getting the description in but I'm missing `min_word_count` col from my node_type.
SELECT `min_word_count` FROM `node_type`;
ERROR 1054 (42S22): Unknown column 'min_word_count' in 'field list'

tobiasb’s picture

min_word_count isn#t anymore in D7.

steinmb’s picture

OK, any other ideas why the patch did not fix the problem?

upandrunning’s picture

Version: 7.x-dev » 7.0-beta2

Did an upgrade from 6.19 to 7 beta 2 and received the following msg when creating content:

* Notice: Undefined index: description in field_multiple_value_form() (line 146 of /home/mysite/public_html/mydir/modules/field/field.form.inc).
* Notice: Undefined index: required in field_multiple_value_form() (line 164 of /home/mysite/public_html/mydir/modules/field/field.form.inc).
* Notice: Undefined index: required in field_multiple_value_form() (line 193 of /home/mysite/public_html/mydir/modules/field/field.form.inc).

tobiasb’s picture

Version: 7.0-beta2 » 7.x-dev
upandrunning’s picture

Installed 7.x-dev as suggested. Same issue.

* Notice: Undefined index: description in field_multiple_value_form() (line 155 of /home/mysite/public_html/mydir/modules/field/field.form.inc).
* Notice: Undefined index: required in field_multiple_value_form() (line 173 of /home/mysite/public_html/mydir/modules/field/field.form.inc).
* Notice: Undefined index: required in field_multiple_value_form() (line 202 of /home/mysite/public_html/mydir/modules/field/field.form.inc).

tobiasb’s picture

You need the patch for D7 before you upgrade from D6 -> D7.

jcarlson34’s picture

This isn't a fix but offers a temporary solution / workaround for avoiding this error message. Seems obvious but this got me around the error:

Before upgrading, just re-add a body field to the content types that don't have them. This is as simple as re-adding the word 'Body' in the Submission Form Settings section of the Content Type edit screen.

Also, add a description to all content types that didn't have them.

Upgrade the site to Drupal 7.

Delete the Body field in Manage Fields in Drupal 7 content types.

jcarlson34’s picture

The patch in #9 (or some other core fix) must have worked because I tried again and upgraded my site with a post D7 beta 3 dev build and forgot to give my node's bodies before I did so.

I have not received the errors in #15 that I did on a previous earlier 7.x dev upgrade. Since no one has posted about this for a while (and I assume people are upgrading their sites in greater numbers) I think it is safe for someone to make this on RTBC.

bojanz’s picture

The fix is correct.

'required' => (isset($node_type->min_word_count) && $node_type->min_word_count > 0) ? 1 : 0,

Might be better as:

'required' => !empty($node_type->min_word_count) ? 1 : 0,

but that's nitpicking.

Leaving the RTBC to someone who has an opinion on the above.

catch’s picture

Or to continue the nitpicking, just:

'required' => (int) !empty($node_type->min_word_count),

anselm.marie’s picture

Ok something strange just happen but in a good way and I need someone to confirm that this works. Follow these steps:

1. Click on Structure > Content types.

2. Click on manage fields for either "page" or "story".

3. Create a new field. Label -> "test", Name -> field_"test", Field -> "Long text and summary", Widget -> "Text area with a summary"

4. Hit save. Now go to an existing story/page or create a story/page.

5. At this step the errors disappeared for me. Go back to the field you just created and delete it.

6. Return back to an existing story/page or create a story/page. The errors should still be gone.

I did this for both story and page nodes and it worked. I hope it does the same for you.

nitmd’s picture

Ran into this problem this morning and tried anselm.marie's solution; easy and it worked for me.

rack88’s picture

Yeah, I had the same problem with a D7 upgrade. anselm.marie's solution worked for me. Seems like a strange issue though.

KarenS’s picture

Even simpler fix -- go the the Manage fields page and just save it. No need to add a new field. Just do that for each content type and the error is gone.

The Manage fields page does not alter the content type definition itself, and it appears that making almost any change to anything fixes this, so I suspect we need to do something like run field_cache_clear() (which happens when you add a field, save the Manage fields page, etc.)

KarenS’s picture

Status: Needs review » Needs work

Confirming part of what I said above, there should be no need to add a value for 'required' or 'description' to the array when the body is created. The docs in field.info.inc clearly say that it is not necessary to add either of those values, that defaults will be created. And the defaults are created in _field_write_instance() in field.crud.inc.

The problem is not that the field was not created correctly, it is that we are still using a (cached) value that is wrong until the caches get cleared.

I tried adding field_cache_clear() to the end of the process that created the field but that didn't quite work. It may requiring manually clearing the cache table where the field settings are stored (as entity_info). There are some static caches in there too, so it may be tricky trying to get this cleared out properly in the update hook.

KarenS’s picture

Ah, the real problem is that the update process uses _update_7000_field_create_instance() instead of field_write_instance(), bypassing those default settings. A better fix would be to ensure that this function sets the same default values that the normal one sets. Because other modules might be relying on this function during the update process.

markandrewsutton’s picture

For those of you just looking to get rid of the error, KarenS solution from #24 worked for me .. .

Mapi99’s picture

#24 works for me aswell.

EnjoyLife’s picture

#24 works for me too. For anyone else having this problem: Go to "Administration > Structure > Content Types." For each content type click on "Manage fields" and just press the save button at the bottom. If you do this for each content type this should fix the problem. Thanks KarenS.

joergent’s picture

#29 does not work for me

randallnet’s picture

#24 works for me too, a thousand thanks ;)

Janne’s picture

#21 seems to have worked for me. Strange issue, though.

deajan’s picture

Version: 7.x-dev » 7.0

Solution #24 worked fine for me. Got that error after D6.15 to D6.20 to D7.0 upgrades.

hcderaad’s picture

#24 did remove the notices, but now i'm stuck with a different field order (attached files are above the body) and reordering them doesnt work.

Dave Sandilands’s picture

Is this another example of basically the same issue?

I had an auto-install done by Fantastico (via CPanel) mistakenly thinking I'd get the latest version. Turned out to be 6.18.
Apart from a few settings in settings.php, which I kept a copy of, I made no changes at all.
Set Drupal to maintainance mode , deleted all the files , copied over latest stable release ,7.1, copied back my settings.php and ran update.php.
No errors reported
Turned on some modules, added a new theme (Danland) and all seemed fine.
Decided to create my 1st piece of content ,using the story type.

instantly got this:

* Notice: Undefined index: description in field_multiple_value_form() (line 156 of /home/dav0206/public_html/mmorpgguides.co/modules/field/field.form.inc).
* Notice: Undefined index: required in field_multiple_value_form() (line 178 of /home/dav0206/public_html/mmorpgguides.co/modules/field/field.form.inc).
* Notice: Undefined index: required in field_multiple_value_form() (line 207 of /home/dav0206/public_html/mmorpgguides.co/modules/field/field.form.inc).

I tried the method mentioned above regarding going to Structure>content types>edit>save(without changing anything) but it didn't have any effect.

Hope you clever people in Drupal land can help because I'm lost (and I can hear the Devil whispering to me,"should have gone to WordPress,O brainless one" )

Update:

I reviewed the suggestion in #24 and noticed I didn't actually do what it said. Having tried again, I can report that it worked perfectly. Faith restored :)

mobonobomo’s picture

Confirming that #24 worked for me as well. I cleared my caches at Configuration > Performance before navigating to the "Manage fields" page for the particular content type and only clicking the "Save" button.

The errors on node/*/edit are gone, but is there some underlying problem that might rear its head in the future?

ryivhnn’s picture

#24 worked. Glad it's a relatively simple fix (for most people), hopefully just as easy to find and fix whatever causes that to happen in the first place :)

philosurfer’s picture

I confirm #24 works as well.

This was a 6.2 to 7.x upgrade.

enfineitz’s picture

#5 worked for me. BUt I am getting another error for the CKeditor, which I’ll need to examine.

Garmisch’s picture

Confirmed. Solution #24 works fine. Got error after D6.20 to D7.0 upgrade.

bug_over’s picture

Status: Needs work » Needs review
Issue tags: -d7sc

#9: drupal_931512.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +d7sc

The last submitted patch, drupal_931512.patch, failed testing.

craigtockman’s picture

#24 worked for me as well. Thanks.

Lugir’s picture

Confirmed. Solution #24 works fine. Got error after D6.20 to D7.0 upgrade.

steinmb’s picture

Version: 7.0 » 8.x-dev
Issue tags: +Needs backport to D7

Need to get fixed in D8 and then backported according to http://drupal.org/node/767608.

Kev’s picture

Upgraded from drupal 6.20 to 7 and run into the same error and it took quite some time to find this report.
#24 solved the issues for me, too.

This should be included in the upgrade instructions.

lishaw1968’s picture

Same situation as Kev, Upgraded from 6.2 to 7, ran into the error, applied the solution
#24, the error is now gone.

senortim’s picture

#24 worked for me as well. (Thanks KarenS!) But I think mine was an upgrade from D7.dev to D7. I was trying a fresh start with D7 for this project! :-)

robinoz’s picture

Version: 8.x-dev » 7.0

#24 worked for me as well. Thanks Karen! My problem followed a fresh install of D7 with Fantastico so I don't think the problem is related to upgrades.

steinmb’s picture

@robinoz: Why did you change version back to 7?

catch’s picture

Version: 7.0 » 8.x-dev
catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
Issue tags: -d7sc, -Needs backport to D7 +Needs tests, +D7 upgrade path
FileSize
655 bytes

Re-uploading #9, moving back to 7.x since this is upgrade path only and 8.x no longer contains the 6.x-7.x upgrades.

If that patch passes tests, ideally we can add an upgrade path test to confirm it fixes the issue. Since there's workaround for existing installs just fixing future upgrades from 6.x-7.x seems OK here, it' s configuration loss rather than proper data loss but enough people ran into it that it's annoying enough to stay major.

k4rtik’s picture

Is this patch required anymore?

#21 worked for me, not sure whether I will face any future problems in this regard.

catch’s picture

FileSize
1.38 KB
761 bytes

Tests only, tests + patch.

@kartiksinghal - if you have a site and you've done the workaround, you don't need to worry about it. However we need to fix it for sites that are yet to upgrade.

catch’s picture

FileSize
1.5 KB
877 bytes

I thought I'd need to change data in the upgrade path to test required, but that was wrong, so extra assertion added - should have two exceptions and two fails without the fix.

catch’s picture

FileSize
1.5 KB

Should use assertIdentical since we have that.

clemens.tolboom’s picture

I reopened #952970: Undefined index: required in field_default_form() as that differs from this issue and patch #56 did not solve it either :-(

This is about

function field_multiple_value_form()

and not

function field_default_form()
marcingy’s picture

Status: Needs review » Reviewed & tested by the community

Patch in 55 looks good

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 7.x. Thanks!

Status: Fixed » Closed (fixed)

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

raefrog’s picture

I just did a clean install to 7.7 and I am getting these errors on both the story and Page content, as well as the Product and Product kit from Ubercart.

steinmb’s picture

That could be Übercart related. pls. verify that you have them on a clean D7 without any extra modules installed.

rolandu’s picture

Upgraded from 6.19 to 7.7 a while ago and later to 7.8. Had the problem all the time until I found this thread.

Reply #24 solved the problem.

However, is this issue really to be considered fixed if the db-upgrades didn't solve it?

egfrith’s picture

I've also had this problem, even after an upgrade from 7.7 to 7.8. The solution at #24 worked for me too.

kbell’s picture

I'm in 7.8 (this is NOT an upgrade from D6 either, just straight D7), latest version of CKEditor, and I'm having the same problem. Solution #24 did NOT work for me, however. What did change was that now when I try to edit or create a new node, the Body field outlines in red before disappearing(!). Ring a bell, anyone? Does this issue belong elsewhere or am I in the right place?

Thanks,
Kelly Bell

ssace’s picture

I just did a upgrade from 6 to 7.12. Got the same error in the POLL content type.

#24 above worked for me to clear the field.form.inc errors

ssace’s picture

Issue summary: View changes

Updated issue summary.