Encountering this PDO exception during Drush make:
WD rules_config: PDOException: SQLSTATE[HY000]: General error: 1364 Field 'plugin' doesn't have a default value: INSERT INTO {rules_config} (name, status, module) VALUES (:db_insert_placeholder_0,
:db_insert_placeholder_1, :db_insert_placeholder_2); Array
(
[:db_insert_placeholder_0] => rules_update_master_installment
[:db_insert_placeholder_1] => 2
[:db_insert_placeholder_2] => product_type_registration_fee
)
in drupal_write_record() (line 6868 of /includes/common.inc).
Here's what the exported Rule looks like:
$items['rules_update_master_installment'] = entity_import('rules_config', '{ "rules_update_master_installment" : {
"LABEL" : "Update Master Installment",
"PLUGIN" : "rule",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : {
"registration_fee" : { "label" : "Registration Fee", "type" : "commerce_product" },
"master_installment" : { "label" : "Master Installment", "type" : "commerce_product" }
},
"IF" : [
{ "data_is" : { "data" : [ "registration-fee:type" ], "value" : "registration_fee" } },
{ "data_is" : { "data" : [ "master-installment:type" ], "value" : "master_installment" } }
],
"DO" : [
{ "data_set" : {
"data" : [ "master-installment:sku" ],
"value" : "[registration-fee:sku]-INITIAL"
}
},
{ "data_set" : {
"data" : [ "master-installment:commerce-price" ],
"value" : [ "registration-fee:field-initial-payment" ]
}
},
{ "data_set" : {
"data" : [ "master-installment:title" ],
"value" : "[registration-fee:title] MASTER INSTALLMENT"
}
},
{ "data_set" : {
"data" : [ "master-installment:field-group-role-reference" ],
"value" : [ "registration-fee:field-group-role-reference" ]
}
},
{ "component_rules_check_disable_master_installment" : {
"registration_fee" : [ "registration_fee" ],
"master_installment" : [ "master_installment" ]
}
},
{ "component_rules_check_enable_master_installment" : {
"registration_fee" : [ "registration_fee" ],
"master_installment" : [ "master_installment" ]
},
{ "og_group_content_add" : {
"entity" : [ "initial-payment" ],
"group" : [ "commerce-product:og-membership:0:group" ]
}
},
{ "entity_save" : { "data" : [ "initial-payment" ], "immediate" : 1 } }
]
}
}');
I should note this is happening on more than one rule. When drush hits these PDO errors though, it eventually crashes out.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | entity-1309144-29-7.x-2.x.patch | 658 bytes | alex.bukach |
| #24 | entity-1309144-24-7.x-2.x.patch | 686 bytes | hughworm |
| #8 | rules-fix-schema-defaults-1309144-8.patch | 1.35 KB | dakala |
Comments
Comment #1
wjaspers commentedFound the cause:
Somehow a few rules got added to an exported feature twice (likely a local modification).
Is there some way to help rules catch this as a bug?
Comment #3
mitchell commentedUpdated component.
Comment #4
jhodgdonI am seeing this exact error today in 7.x-2.2 in trying to use the default rules configs hook. But in my case I am certain they are not defined twice. So I am opening up this issue again...
Comment #5
erik seifert commentedSame to me. Creating a module with default rules. Import over UI -> no problem. Import over Module enabling -> crash
Comment #6
phenaproximaI have this problem too, only with the 'name' field instead of 'plugin'.
Comment #7
ptmkenny commentedComment #8
dakalaNoticed this problem during a fresh install with a distribution profile. A related issue (https://drupal.org/node/1952170) suggests this might be due to invalid JSON in an exported rule. I've successfully imported my 2 rules, using the form at admin/config/workflow/rules/reaction/import without any problem.
The attached patch provides defaults for "name" and "plugin" columns of the rules_config table.
Comment #9
imiksuI wonder if this could be caused by updating a module which introduces a new attribute to an action or condition and existing rules aren't providing them?
Also, are you using webform rules module? In my update this is a new module introduced o.O
Comment #10
Paul B commentedI get the same error after adding a rule that has a dependency on rules_scheduler to an existing Feature, and then updating the feature on a system where rules_scheduler is not enabled.
(The rules_scheduler module was added to the dependencies of the feature module, but since the feature module was already enabled that didn't help.)
Comment #11
deales commented@paul-b
I had the same situation and issue with rules_scheduler. I performed these steps:
After this I had no problems when myfeature module was enabled.
Comment #12
a.milkovskyDebug RulesEntityController::import(). Follow the $error_msg message parameter. That should tell you the issue(could be missing module dependency or plugin, etc).
The big issue that $error_msg result is not shown anywhere. It should be logged! See entity_import(). Currently all rules default configurations are imported via entity_import().
Possible solution: fork entity_import() function with use of $error_msg parameter.
Comment #13
fagoNot sure which $error_msg you mean, could you clarify where it's dropped? If it's a bug in entity module we should fix it there.
Comment #14
fagoah, I see the error message is a Rules specific extensions which is only used at the Rules import form.
I'd suggest rolling patch which:
- changes rules_import() a bit to have a NULL default and keep calling it from the UI with some empty array as initialisation
- throws a new RulesImportException if the error_msg parameter is NULL - so it's easy to catch errors.
- documents the changes for rules_import() and the controllers import() method.
Comment #15
benstallings commentedHere's a patch that resolved the error on my site, by including plugin in the list of fields to insert.
Comment #16
benstallings commentedPlease disregard the patch in #15 above. The problem turned out to be a missing } in my export file.
Comment #17
a.milkovskyHid patch #15 as @BenStallings asked.
Comment #18
jessehsI'll add to the number of people that said this was caused by a module that was not enabled that was required by the rule. In my case it was the acquia_purge module. Enabling the module solved the problem.
It would be nice if there was a better error message for the exception for this though... :)
Some additional notes:
Comment #19
legolasboSame problem here. In my case rules_conditional was disabled.
Perhaps the import functionality could check for required modules and enable them or skip importing the rule if they are not installed?
Comment #20
mikemadison commentedI ran into a similar problem recently, and can confirm that the issue evaporates as soon as all of the proper modules are enabled on the site (or added as a dependency to the feature, which effectively does the same thing).
Agree with #19 that before a rule can be imported it should check to see if the required modules are present and enabled, and be skipped otherwise.
Comment #21
joksanen commentedRunning into this issue.. Removing all rules on the site cleared it, but re-adding them in code has brought the issue up again.. Stuck currently. All dependencies should be enabled.
Comment #22
RAWDESK commentedSubscribing #19 too:
We had a similar issue after a feature recreate containing a by Rules UI created rule.
At deployment to our staging environment, this error occurred on drush updb or drush rr.
Solved it by reverting the feature right before the updb or rr.
Apparently rules_schema() in rules.install was indirectly causing the lack of name and plugin attributes, caused by the unreverted feature.
A bit different case, but i agree with legolasbo this should be tackled during import, assisted by a watchdog log.
Comment #23
hughworm commentedIn my site this was caused by MODULE_default_rules_configuration in MODULE.rules_defaults.inc returning a pointer to FALSE where there should be an entity, if RulesEntityControler::import() rightly determines that a dependency module (e.g. rules_scheduler) is missing. The features code doesn't test whether an entity was successfully imported, and Entity doesn't either, and tries to use FALSE as an object. This results in a php warning, the DB error when Entity tries to write the malformed object, and general pandemonium.
The real fix I think is for features to test the import before returning it to Entity. e.g.
I'll work on a patch for this in features module.
Comment #24
hughworm commentedThe code to make a fix as #23 would have to go in function export_render, but it's a bit messy and would be simpler (and possibly more robust) to fix the import stage in _entity_defaults_rebuild, which the attached patch attempts to do.
This patch fixes the issue of a rules in features causing a DB error if a depended module is not enabled.
I've raised an issue on Entity to try to get this fix in there - https://www.drupal.org/node/2829437#comment-11790019
Comment #25
bburgFor me, the site I was working on had the Rules module in the sites/all/modules directory (note, not /contrib), and not the sites/all/modules/contrib directory. This somehow caused drush commands to show that the Rules module was not installed, however, looking at the modules page showed that it was.I moved the Rules module folder to the sites/all/modules/contrib and ran registry rebuild. I don't know if only one of those steps was actually necessary or not.Edit: Ok, so I had to revert features a few times. The issue was that something had been exported to a Features module, and I had to revert that specific module first (so fra wasn't working).
Comment #26
othermachines commentedInterestingly, this error arose for me because I had a message in my exported rule that contained ASCII "\r\n". Error went away when I replaced it with Unicode "\u000D\u000A".
Comment #27
bboty commentedIf it's of any help, last time I got this error it was because a rule condition's value was badly formatted, similar to @othermachines problem.
Comment #28
reyk86 commented#24 works for meComment #29
alex.bukach commentedFixed path in the patch.
Comment #30
alex.bukach commentedComment #31
tr commented#24 and #29 are patches for the Entity module, not for Rules.
The Entity API module has an issue open for this, as mentioned in #24. See #2829437: PDO Exception with Rules . Please participate in that issue if you want to see this fixed!
Comment #32
benstallings commented