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

Files: 
CommentFileSizeAuthor
#2 rules-long_machine_names_mishandled-1548474-2.patch782 bytesacrollet
FAILED: [[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 ]

Comments

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

Component:Rules Engine» Rules Core
Status:Active» Needs review
StatusFileSize
new782 bytes
FAILED: [[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 ]

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.

Component:Rules Core» User Interface

changing component.

Assigned:Unassigned» klausi

Patch works as advertised.

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

Assigned: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.

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.

Status:Fixed» Closed (fixed)

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

Status:Closed (fixed)» Active

Long rule names / machine names are still mishandled when cloning a rule and giving it a really long name.
Same fatal SQL exception as OP.

To reproduce: Clone a rule with a 64-char machine name.