Download & Extend

Long rule names are mishandled

Project:Rules
Version:7.x-2.x-dev
Component:User Interface
Category:bug report
Priority:normal
Assigned:fago
Status:closed (fixed)

Issue Summary

Rules module is not handling too long rule names properly. No message is displayed that users should not use long names and the system throws PDOException.
On a production system, where error messages are disabled, users will not see what is the reason for this error.

Steps to reproduce

1. go to Configuration>Workflow>Rules in /admin/config/workflow/rules
2. click Add Rule button

the site redirects to /admin/config/workflow/rules/reaction/add

3. Enter following rule name:
"This is a long name of a rule test example 12345678901234567890"
Machine-readable name will be set to "this_is_a_long_name_of_a_rule_test_example_12345678901234567890"

4. Enter any event name into React on event

5. Click Save

Error

"Error
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, dirty, module, access_exposed, 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, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => rules_this_is_a_long_name_of_a_rule_test_example_12345678901234567890 [:db_insert_placeholder_1] => This is a long name of a rule test example 12345678901234567890 [:db_insert_placeholder_2] => reaction rule [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => rules [:db_insert_placeholder_7] => 0 [:db_insert_placeholder_8] => O:17:"RulesReactionRule":13:{s:9:"*parent";N;s:2:"id";N;s:12:"*elementId";i:1;s:6:"weight";i:0;s:8:"settings";a:0:{}s:4:"name";s:70:"rules_this_is_a_long_name_of_a_rule_test_example_12345678901234567890";s:6:"module";s:5:"rules";s:5:"label";s:64:"This is a long name of a rule test example 12345678901234567890";s:4:"tags";a:0:{}s:11:"*children";a:0:{}s:7:"*info";a:0:{}s:13:"*conditions";O:8:"RulesAnd":8:{s:9:"*parent";r:1;s:2:"id";N;s:12:"*elementId";i:2;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:12:"comment_view";}} ) in drupal_write_record() (line 6975 of /***/includes/common.inc).
The website encountered an unexpected error. Please try again later."

Environment

Drupal 7.12
mysql

Comments

#1

Title:PDOException Data too long for column 'name' - error handling missing» Long rule names are mishandled

#2

Component:Rules Engine» Rules Core
Status:active» needs review

This issue is a follow-on from #1227018: 32 chars too small for rules names?. The maxlength on the machine_name field for the Rule name is set to 64 chars, which should be fine since that's the length of the name field in the rules_config schema. However, the string 'rules_' is pre-pended to machine names before saving, resulting in the error in the OP. Patch attached reduces the maxlength of the machine_name field, eliminating this error.

AttachmentSizeStatusTest resultOperations
rules-long_machine_names_mishandled-1548474-2.patch782 bytesIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch rules-long_machine_names_mishandled-1548474-2.patch. Unable to apply patch. See the log in the details link for more information.View details

#3

Component:Rules Core» User Interface

changing component.

#4

Assigned to:Anonymous» klausi

Patch works as advertised.

Maybe setting a form error would be possible before the form is submitted though.

#5

Assigned to:klausi» fago

Not sure this is the right fix. Maxlength of the machine name depends on the module that provides the Rules plugin that is being created. The module name is the automatic prefix of the machine name. So maxlength varies with the module that provides the plugin.

However, in 99% of all cases Rules itself will be the provider, so we could just commit this pragmatic approach for now to avoid PDOExceptions. I pass this on to fago, as he knows best how to fix this.

#6

Status:needs review» fixed

ouch. Well, I doubt anyone makes use of the UI and changes the module prefix right now, so let's be pragmatic for now and do it as is. Thanks, committed.

#7

Status:fixed» closed (fixed)

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