The latest changes to rules database schema breaks commerce module install and possibly other modules too:

In this example, the rule failing to install is 'commerce_checkout_order_status_update', which is 37 characters long, but 'name' is suddenly only 32 characters wide. It seems unreasonable to change the rules on how long a rule name can be at this point of the game.

WD rules_config: PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1: INSERT INTO {rules_config} (name, label, plugin, active, weight, status, module, data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => commerce_checkout_order_status_update [:db_insert_placeholder_1] => Update the order status on checkout completion [:db_insert_placeholder_2] => reaction rule [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 2 [:db_insert_placeholder_6] => commerce_checkout [:db_insert_placeholder_7] => O:17:"RulesReactionRule":13:{s:9:"*parent";N;s:2:"id";N;s:12:"*elementId";N;s:6:"weight";i:0;s:8:"settings";a:0:{}s:4:"name";s:37:"commerce_checkout_order_status_update";s:6:"module";s:17:"commerce_checkout";s:6:"status";i:2;s:5:"label";s:46:"Update the order status on checkout completion";s:11:"*children";a:1:{i:0;O:11:"RulesAction":6:{s:9:"*parent";r:1;s:2:"id";N;s:12:"*elementId";N;s:6:"weight";i:0;s:8:"settings";a:3:{s:21:"commerce_order:select";s:14:"commerce-order";s:11:"order_state";s:7:"pending";s:18:"#_needs_processing";b:1;}s:14:"*elementName";s:27:"commerce_order_update_state";}}s:7:"*info";a:0:{}s:13:"*conditions";O:8:"RulesAnd":8:{s:9:"*parent";r:1;s:2:"id";N;s:12:"*elementId";N;s:6:"weight";i:0;s:8:"settings";a:0:{}s:11:"*children";a:0:{}s:7:"*info";a:0:{}s:9:"*negate";b:0;}s:9:"*events";a:1:{i:0;s:26:"commerce_checkout_complete";}} ) in drupal_write_record() (line 6859 of /var/aegir/platforms/xxx/includes/common.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EclipseGc’s picture

Component: Rules Core » Rules Engine

Just lost 6 hours trying to track this in an install profile :-S

Dave Reid’s picture

http://drupalcode.org/project/rules.git/commitdiff/db1c6758eb0f31ab0de7f...

When you shorten column lengths in hook_schema()s, you have to also add hook_update_N()s with db_change_field() with the new spec.

EclipseGc’s picture

Quick patch to 128.

EclipseGc’s picture

Status: Active » Needs review
FileSize
375 bytes

oops, failed to actually grab the patch

EclipseGc’s picture

FileSize
367 bytes

Adding a p0 patch for drush make.

rfay’s picture

Category: support » bug
Priority: Normal » Critical

This is a fundamental #fail: Can't install at all.

rfay’s picture

@EclipseGC, Drush Make now supports normal patches. Fix went in 10 days ago or so (finally).

rfay’s picture

Issue summary: View changes

Added more analysis of the error message.

rfay’s picture

Status: Needs review » Needs work

Updated issue summary with more detail.

We probably need to just go back to 255 characters, unless there's some reason not to.

If this is going to be shortened, it needs to have a db_change_field() and also the index has to be removed and rebuilt in hook_update_N().

fago’s picture

ouch, sry for creating those troubles.

The UI has already #maxlength == 32 so I thought this is a safe change. Obviously it isn't... :(
I see that programmatically created rules don't have to follow that though, in particular as we don't support name changes there anyway. Anyway, we should sync both values.

Problem is, we also need an index in the mysql rules_scheduler table, but mysql is by default limited to 1000byte indexes and it looks like db-tng doesn't support changing that. With utf8, we have varcharsize*3 for the index, what means with the index (machine_name, identifier) we cannot have 255*3+255*3 (>1000).

I think it doesn't make much sense to have that long machine-names, as it just makes identifying slower/harder. 32 should be basically enough, but I see might be a bit less in certain operations. So what about 64?

64*3+255*3 would work.

What's the longest machine-readable name in drupal commerce? Any reason to have such long names there?

>If this is going to be shortened, it needs to have a db_change_field() and also the index has to be removed and rebuilt in hook_update_N().

That's painful for such a "small change", but yes we need to that.

rfay’s picture

Thanks, fago. I suspect 64 would be OK. (Note that feeds had the key length problem recently as well, #1044882: table feeds_item could not be created pdo exception key was too long)

In the below, it looks to me like the second one was probably created with the UI.


select name, length(name) as fieldlength from rules_config order by fieldlength desc limit 10

name fieldlength
commerce_payment_commerce_payment_example 41
rules_message_to_user_when_saving_comm 38
commerce_checkout_order_status_update 37
commerce_cart_order_status_reset 32
commerce_checkout_order_convert 31
commerce_checkout_order_email 29
commerce_checkout_new_account 29
commerce_tax_type_sales_tax 27
rules_setpricetosomething2 26
rules_setpriceandbulklmit 25
EclipseGc’s picture

Yeah, I think the tendency has been toward longer names since, at least as I understand it, Drupal Commerce did not want to repeat the ubercart methodology and prefix every thing as dc/uc, and instead opted for "commerce_". It would be good if we didn't have to break that methodology for rules, and I THINK we can live in 64 (I just changed things back to 255 via the above patch any time we're working with dev, so I've not actually tested it).

commerce_checkout_order_status_update is the specific ruleset that kills most installs, but we only know that because we hacked at our dependencies until we figured it out. Hopefully we can live in 64 as well. It'd be good to hear from Ryan on this, but I think he's still on vacation.

Eclipse

fago’s picture

Status: Needs work » Needs review
FileSize
3.31 KB

ok, so here is patch fixing it to 64. Please test!

>In the below, it looks to me like the second one was probably created with the UI.
hm, I guess that might have been caused by bug that was in the machine-name generation of core. It didn't respect the max-length value, so longer values might have been auto-generated due to that. The core bug has been already fixed though, so it should not happen any more.

recidive’s picture

Status: Needs review » Needs work

Commerce module install works again after applying the patch.

After running the update, the rules_config table is changed fine:

mysql> describe rules_config
    -> ;
+--------+--------------+------+-----+-----------+----------------+
| Field  | Type         | Null | Key | Default   | Extra          |
+--------+--------------+------+-----+-----------+----------------+
| id     | int(11)      | NO   | PRI | NULL      | auto_increment |
| name   | varchar(64)  | NO   | UNI | NULL      |                |
| label  | varchar(255) | NO   |     | unlabeled |                |
| plugin | varchar(127) | NO   | MUL | NULL      |                |
| active | int(11)      | NO   |     | 1         |                |
| weight | tinyint(4)   | NO   |     | 0         |                |
| data   | longblob     | YES  |     | NULL      |                |
| status | tinyint(4)   | NO   |     | 1         |                |
| module | varchar(255) | YES  |     | NULL      |                |
+--------+--------------+------+-----+-----------+----------------+
9 rows in set (0,07 sec)

I don't have rules_scheduler enabled to test the upgrade, but looking at the patch I see rules_scheduler_update_7202() update the rules_config table again, when it should update the rules_scheduler table?

fago’s picture

Status: Needs work » Needs review
FileSize
3.2 KB

thanks.

ok, I've fixed that and tested it on another site. However, the rules-scheduler update failed to create the new keys via db_change_field() - I don't know why as it works for the rules update. Reverting to a db_add_unique_key() worked for me.

So this could need another tester who makes sure the upgrade works and all indexes have been properly created.

ezra-g’s picture

I applied #14 and the database update ran successfully.

mysql> desc rules_config;
+--------+--------------+------+-----+-----------+----------------+
| Field  | Type         | Null | Key | Default   | Extra          |
+--------+--------------+------+-----+-----------+----------------+
| id     | int(11)      | NO   | PRI | NULL      | auto_increment |
| name   | varchar(64)  | NO   | UNI | NULL      |                |
| label  | varchar(255) | NO   |     | unlabeled |                |
| plugin | varchar(127) | NO   | MUL | NULL      |                |
| active | int(11)      | NO   |     | 1         |                |
| weight | tinyint(4)   | NO   |     | 0         |                |
| status | tinyint(4)   | NO   |     | 1         |                |
| module | varchar(255) | YES  |     | NULL      |                |
| data   | longblob     | YES  |     | NULL      |                |
+--------+--------------+------+-----+-----------+----------------+
9 rows in set (0.20 sec)
recidive’s picture

Status: Needs review » Reviewed & tested by the community

I tested upgrading rules schedule module, bellow is the rules_scheduler table structure before and after running the schema update:

Before:

mysql> describe rules_scheduler;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| tid        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| config     | varchar(32)      | NO   |     |         |                |
| date       | int(11)          | NO   | MUL | NULL    |                |
| state      | text             | YES  |     | NULL    |                |
| identifier | varchar(255)     | YES  |     |         |                |
+------------+------------------+------+-----+---------+----------------+
5 rows in set (0,02 sec)

After:

mysql> describe rules_scheduler;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| tid        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| config     | varchar(64)      | NO   | MUL |         |                |
| date       | int(11)          | NO   | MUL | NULL    |                |
| state      | text             | YES  |     | NULL    |                |
| identifier | varchar(255)     | YES  |     |         |                |
+------------+------------------+------+-----+---------+----------------+
5 rows in set (0,00 sec)
fago’s picture

Status: Reviewed & tested by the community » Fixed

thanks, committed.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

More detail on #fail analysis

dobe’s picture

I have a problem... 64 characters is too small for my name fields for Commerce Pickup module my rule name ends up looking like this: commerce_shipping_service_commerce_pickup__commerce_customer_profile__23197

I did a custom patch for my situation, is it really necessary to limit this field so much?