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.

Comments

wjaspers’s picture

Status: Active » Fixed

Found 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?

Status: Fixed » Closed (fixed)

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

mitchell’s picture

Component: Feature module support » Provided Module Integrations

Updated component.

jhodgdon’s picture

Component: Provided Module Integrations » Module Integrations
Status: Closed (fixed) » Active

I 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...

erik seifert’s picture

Same to me. Creating a module with default rules. Import over UI -> no problem. Import over Module enabling -> crash

phenaproxima’s picture

I have this problem too, only with the 'name' field instead of 'plugin'.

ptmkenny’s picture

Title: PDO Exception » PDO Exception SQLSTATE[HY000]: General error: 1364 Field 'plugin' doesn't have a default value
Priority: Critical » Major
dakala’s picture

StatusFileSize
new1.35 KB

Noticed 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.

imiksu’s picture

I 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

Paul B’s picture

I 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.)

deales’s picture

@paul-b
I had the same situation and issue with rules_scheduler. I performed these steps:

  1. Disable myfeature module
  2. Disable rules_scheduler module
  3. Uninstall rules_scheduler module
  4. Enable myfeature module

After this I had no problems when myfeature module was enabled.

a.milkovsky’s picture

Debug 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.

fago’s picture

Not 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.

fago’s picture

ah, 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.

benstallings’s picture

Status: Active » Needs review
StatusFileSize
new1.25 KB

Here's a patch that resolved the error on my site, by including plugin in the list of fields to insert.

benstallings’s picture

Status: Needs review » Active

Please disregard the patch in #15 above. The problem turned out to be a missing } in my export file.

a.milkovsky’s picture

Hid patch #15 as @BenStallings asked.

jessehs’s picture

I'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:

  1. When viewing the feature via the UI, the Rules component appeared overridden, and would not revert.
  2. When visiting the Rules Admin page, the rule did not appear.
  3. When importing the Rule manually via the UI, I got a helpful error message "required module Acquia Purge is missing"
legolasbo’s picture

Same 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?

mikemadison’s picture

I 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.

joksanen’s picture

Running 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.

RAWDESK’s picture

Subscribing #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.

hughworm’s picture

In 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.

/**
 * Implements hook_default_rules_configuration().
 */
function MODULE_default_rules_configuration() {
  $items = array();
  $entity = entity_import('rules_config', '{ "rules_my_rule" : { ... }');
  // Only return valid entities (ie not FALSE)
  if ($entity) {
    $items['rules_my_rule'] = $entity;
  }
  ...
  return $items;
}

I'll work on a patch for this in features module.

hughworm’s picture

StatusFileSize
new686 bytes

The 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

bburg’s picture

For 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).

othermachines’s picture

Interestingly, 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".

bboty’s picture

If 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.

reyk86’s picture

#24 works for me

alex.bukach’s picture

StatusFileSize
new658 bytes

Fixed path in the patch.

alex.bukach’s picture

Status: Active » Needs review
tr’s picture

Status: Needs review » Active

#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!

benstallings’s picture

Status: Active » Closed (outdated)

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.