I am testing migration of my current drupal site (5.10) to 6.4.
My site uses CCK for a recipe node type.
All the fields in the recipe node are text fields. I have one multiple value field (ingredients).

I used cck-5.x-1.9 as suggested before upgrading.

After upgrading to 6.4, I have tried both 6.x-2.0-rc7 and 6.x-2.x-dev versions of CCK and observed the same issue as described below.

I have followed all the usual upgrade instructions (disable all modules, use bluemarine theme). Upgrade core. Add one module at a time, visit update.php and then enable the module etc.

After upgrading from 5.10 to 6.4 I observe that:
1. When I try to create a new node of type 'recipe', enter data and hit save, only title and ingredients (which is a multiple value field) get saved. But all the other text fields preparation time, source, additional note and instructions are lost. The preview shows these things, but after submit they are lost. And sure enough I check the mysql database, and these fields are empty.
2. However, if I edit an existing node of recipe type (that migrated from 5.10 existing data), and make changes and save it, it does get saved properly.
3. Another interesting observation is: If I create a new node type (say new_recipe) and reuse exactly the SAME fields again for this node type, and then create new nodes of type 'new_recipe' I see that the data is stored properly. But for the original node type 'recipe' I see problem reported in #1.

So it seems something is going wrong between preview and save, where the custom fields data gets lost only for the node type that migrated from 5.x to 6.x.

Because of this but I'm stuck at 5.10 and can't upgrade to 6.4.

I understand that cck for 6.x is still in RC, but I thought I would report this issue so it gets fixed before cck comes out of RC.

If you need any more information please let me know and I'll try to post it here.

CommentFileSizeAuthor
#10 cck-secure-updates.patch13.9 KByched

Comments

yched’s picture

Please contact me through my contact form - If that's possible, I'd like to take a look at a db dump...

amitbapat’s picture

Replied through your contact form.

amitbapat’s picture

I found one more thing, when I leave the 'notes' field blank, I see the problem reported in the original post. If I fill in the notes field, there is no problem with creating new nodes of type recipe. Strange problem indeed. Today I'm using the 'dev' version released on September 21, 2008.

haa haa haa! the date is wrong, how could I use version released in future? It should be Sept 20.

yched’s picture

OK, I can reproduce that behavior with the db dump you sent me - including the odd stuff in #3.
Now, I need to find what the hell is happening...

yched’s picture

OK, got it - your site was configured so that error messages were not displayed, so this was 'hidden'

Actually comment #3 was the key. Problem is that the 'format' columns of your text fields are set to NOT NULL.
Thus leaving the 'notes' field blank causes a 'Column 'field_notes_format' cannot be null' error and the whole insert fails for the fields that are stored in the same table (that is, all fields except the one that is multiple)

Strange, because text_update_6001() is supposed to take care of this. Your dump shows that you ran it, though.
I'll look into this.

amitbapat’s picture

You are correct. The one workaround I have found is to make the 'Notes' field required, and set default value to 'none' so that even if user doesn't enter anything, 'none' will be stored in the '_value' field and '_format' gets automatically take care through default.

So do I need to change the notes_format field to from NOT NULL to NULL? Is that all? If I do a manual 'ALTER TABLE' on the content_type_recipe table, will that solve my problem and save me from going through the upgrade process all over again?

yched’s picture

In the case of your specific site, yes, manually changing the 2 *_format columns in your content_type_recipe table to allow NULL values (and default to NULL) should solve the issue without further messing with the updates.

The only case where I could reproduce "D5->D6 upgrade does not update _format columns to allow NULL" is when the CCK updates are run while CCK modules are still disabled.
amitbapat : can you confrim that you uploaded the CCK D6 files and ran the updates *before* actually enabling the modules ?

Karen : problem in such case ("user runs CCK updates while CCK modules are still disabled") is that content_types_install(), which relies on module_list() / module_invoke() returns an empty array, so updates such as text_update_6001() return without actually doing anything.
Sigh. Update.php updating disabled modules is really a massive pain when it comes to CCK. I guess I should have helped weighing against it, dunno where I was back then...

OK, well. We already added some logic to abort field module updates until content_update_6000 has run. It seems we also need to abort each module's updates unless that module *and* content.module are both enabled. To be future-proof and secure future updates as well, I think we need to do that check in *every* update function, not just the first ones in the D5->D6 upgrade path. The enforced behaviour would then be :
- no updates for cck fields run until content.module still has pending updates (using drupal_get_schema_versions() and drupal_get_installed_schema_version())
- no updates for content.module and field modules run unless the modules are enabled.
We can probably provide a helper function in content.install to reduce the code duplication in each update function of each field module...

Then we'll also need to find a way to fix existing CCK RC installs, but first I'd like amitbapat to confirm my hypothesis above, to be sure we're chasing the right rabbit.

amitbapat’s picture

yched: Yes, that is correct. As suggested in the upgrade guide, I disabled all the modules in preparation for upgrade. Then replaced all 5.10 files, removed all the sites/all/modules directories. Then performed upgrade of all the core modules. Then added cck 6.x version to sites/all/modules and upgraded it, before enabling the module. There is a conundrum here: I can't enable the modules before upgrading, and as you indicate, before enabling the module the upgrade won't happen correctly.

yched’s picture

Title: New nodes created don't save data properly, upgraded from 5.10 to 6.4 » D6 Upgrade path broken when CCK modules are disabled

Thks for reporting back.
"As suggested in the upgrade guide" : Can you spot a specific page ? The doc I can find only deals with core upgrade, and stays really vague on contrib. I cannot find a place in the docs where it is written you should keep contrib modules disabled before running their updates. I'm a little dubious about this, since updates weren't executed for disabled modules until D6.

Anyway. Whether it's the recommended way or not, people *are* going to hit this, so we need to fix it...

yched’s picture

Status: Active » Needs review
StatusFileSize
new13.9 KB

Attached patch does what I proposed in #7. If no-one objects, I'll commit this shortly and update http://drupal.org/node/191796.

Now, we also need to fix CCK installs upgraded from D5 to an RC, that are potentially broken if the updates where run with the modules still disabled.
If I'm not mistaken, problematic functions are the ones that call content_types_install() or content_associate_fields().
That is : optionwidgets_update_6000(), text_update_6000(), text_update_6001().

Simply re-running text_update_6001 should not have evil effects on the installs where it has already run, so this should be as simple as :

function text_update_6002() {
  return text_update_6001();
}

I didn't look closely into the other 2 (the ones that call content_associate_fields() - not sure what would be the effect of having this function ran twice)

amitbapat’s picture

yched: I followed instructions from here. I also watched the screencast from (masteringdrupal.com). You are right it is not clearly mentioned anywhere that modules should be upgraded AFTER they're enabled. So I just applied my logic.

Thanks for your help.

karens’s picture

This looks like a reasonable approach to me, and the helper function is nice -- makes it easier for other modules to do the same thing.

I think it is safe to run content_associate_fields() more than once, I've done it and seen no problems. It will set active modules to active and sets the module names in the database. If that data is already there, it will just get updated again, which shouldn't hurt anything.

None of this will fix disabled contrib modules that are in the modules folder that don't do this testing -- they will still break things and there is not really much we can do about that except try to get the word out.

yched’s picture

I committed the patch in #10

yched’s picture

Status: Needs review » Fixed

And I added updates to re-run optionwidgets_update_6000(), text_update_6000(), text_update_6001().

Anonymous’s picture

Status: Fixed » Closed (fixed)

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