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:
- Install Content and FileField
- Add a new FileField (default settings, single value) to the "story" type
- Make a new story and upload something into the FileField
- Edit the FileField, and change it to "Unlimited" data storage
- 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?
Comment | File | Size | Author |
---|---|---|---|
#13 | cck_fix_serialization-407446-13.patch | 3.98 KB | yched |
#3 | cck_fix_serialization-407446-3.patch | 2.9 KB | yched |
content_double_serialize.patch | 1002 bytes | quicksketch |
Comments
Comment #1
yched CreditAttribution: yched commentedIndeed. 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.
Comment #2
quicksketchThanks yched, much appreciated! I can do some silly unserialize loop() on data load in the mean time in FileField.
Comment #3
yched CreditAttribution: yched commentedHere'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.
Comment #4
k74 CreditAttribution: k74 commentedthe patch ck_fix_serialization-407446-3.patch working properly
Comment #5
Poieo CreditAttribution: Poieo commentedI've applied both of these patches and my view is still displaying an 'a'. Is there something else I need to do?
Comment #6
k74 CreditAttribution: k74 commentedEdit and delete description, save, see ok?
Comment #7
yched CreditAttribution: yched commentedYou did run update.php after applying the patch in #3, right ?
Comment #8
quicksketchPoieo: 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.
Comment #9
Poieo CreditAttribution: Poieo commentedquicksketch: Sorry, you're right. I am only having this problem in views. The field displays fine on the full node.
Comment #10
Leeteq CreditAttribution: Leeteq commentedSubscribing.
Comment #11
TyraelTLK CreditAttribution: TyraelTLK commentedSubscribing
Comment #12
dvc9 CreditAttribution: dvc9 commentedSubscribing...
Comment #13
yched CreditAttribution: yched commentedOK, 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.
Comment #14
yched CreditAttribution: yched commentedI 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.