I found a bug in the uc_attribute module for UC-2 Drupal 6.

The Schema for the table uc_product_adjustments has a field combination, which is described as A serialized array whose keys are attribute IDs and values are option IDs.

In order for drupal_write_record to work the schema must be set to serialize for a field holding a serialized array. Drupal Schema API specifies a key 'serialize': A boolean indicating whether the field will be stored as a serialized string

The key is not set for the uc_product_adjustments table. This causes problems when saving a record using drupal_write_record if you pass in an array for the combination field.

SOLUTION:

File: uc_attbibute.install

Around line 355. Add 'serialize' => TRUE to the definition for 'combination'

So it reads

     'combination' => array(
        'description' => t('A serialized array whose keys are attribute IDs and values are option IDs.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
	'serialize' => TRUE  // added this line
      ),
CommentFileSizeAuthor
#4 621210-attribute-schema-serialize.patch487 byteslongwave

Comments

selinav’s picture

how to do this in my base when the module is ever installed?

Ira Rabinowitz’s picture

I don't understand?

tr’s picture

Category: bug » feature
Status: Active » Needs work

Reclassifying as a feature request because the module works as-is - Ubercart doesn't use drupal_write_record() for this table. But this sounds like a change we should make going forward. Can you put your fix into patch form, and also change the existing queries on that table to use drupal_write_record()?.

longwave’s picture

Version: 6.x-2.0 » 7.x-3.x-dev
Status: Needs work » Needs review
StatusFileSize
new487 bytes

Let's see what testbot thinks of this.

longwave’s picture

Status: Needs review » Fixed

Committed to 7.x. Not sure we should change this now in 6.x, just in case there's existing code relying on the old behaviour and serializing things before calling drupal_write_record().

Status: Fixed » Closed (fixed)

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