This issue arises out of #402860: Fatal error: CCK data field not always unserialized, where we've been experiencing some troubles with FileField's serialized "data" column. It looks like CCK is using a raw SELECT query to pull out data, and then using drupal_write_record() to reinsert data. Currently this isn't taking into account serialized columns, so every time this happens data ends up being reserialized.

To Reproduce:

  1. Install Content and FileField
  2. Add a new FileField (default settings, single value) to the "story" type
  3. Make a new story and upload something into the FileField
  4. Edit the FileField, and change it to "Unlimited" data storage
  5. Edit the FileField again, and change it back to a limit of "1"

Expected: The "field_[field_name]_data" column contains a serialized array.

a:1:{s:11:"description";s:0:"";}

Actual: The "field_[field_name]_data" column contains a double-serialized string

s:32:"a:1:{s:11:"description";s:0:"";}";

Switching the number of values from Unlimited to 1 multiple times serializes the data an additional time every toggle.

a:1:{s:11:"description";s:0:"";}
s:32:"a:1:{s:11:"description";s:0:"";}";
s:40:"s:32:"a:1:{s:11:"description";s:0:"";}";";
s:48:"s:40:"s:32:"a:1:{s:11:"description";s:0:"";}";";";

Attached is a patch which unserializes data before the drupal_write_record() to prevent this from happening. I wrote an upgrade path for FileField in the other issue (http://drupal.org/node/402860#comment-1370000), but it didn't take into account multiple serializations. Should we update it an include it as a CCK update?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

Status: Needs review » Active

Indeed. Committed (slightly refactored). Thanks !

I guess the multi-serialized fix should go in CCK as well, to catch other potentially affected field types :-(
Working on a generic fix, from your filefield_update_6102. Not sure I'll be able to finish it tonight, I'll post what I have.

quicksketch’s picture

Thanks yched, much appreciated! I can do some silly unserialize loop() on data load in the mean time in FileField.

yched’s picture

Status: Active » Needs review
FileSize
2.9 KB

Here's an attempt, seems to work fine, but I'd like more eyes on this.
I did not actually test with large tables (more than $limit rows)

*WILL POTENTIALLY EAT YOUR SITE'S DATA, DO NOT USE* :-)

+ I committed a fix for PHP notices with the content.admin.inc fix that already went in.

k74’s picture

Version: 6.x-2.x-dev » 6.x-2.2

the patch ck_fix_serialization-407446-3.patch working properly

Poieo’s picture

I've applied both of these patches and my view is still displaying an 'a'. Is there something else I need to do?

k74’s picture

Edit and delete description, save, see ok?

yched’s picture

You did run update.php after applying the patch in #3, right ?

quicksketch’s picture

Poieo: If you're having the problem specifically in Views and the normal node displays fine, then the problem your describing is caused by #299329: No display of alt or title with images - Simple Workaround, which the patch in this issue will not fix.

Poieo’s picture

quicksketch: Sorry, you're right. I am only having this problem in views. The field displays fine on the full node.

Leeteq’s picture

Subscribing.

TyraelTLK’s picture

Subscribing

dvc9’s picture

Subscribing...

yched’s picture

OK, tested this on large datasets, turns out a number of things were wrong in the update func.
Attached patch should be fine. I'll commit this shortly.

yched’s picture

Status: Needs review » Fixed

I asked effulgentsia (maintainer of Flexifield) to check the update didn't break anything on his side, but didn't hear from him. Committed the patch in #13.

Status: Fixed » Closed (fixed)

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