These 3 issues might have to do with the rules module and how I use it.
#444947: Duplicate entry error
#445034: Duplicate entry error when saving a node with rules.module
#270777: Duplicate entry when saving a node with rules.module

Here's the rule
Event: After saving new content
Actions: Save a content

Comments

mitchell’s picture

Component: Module Integrations » Miscellaneous
Status: Active » Postponed (maintainer needs more info)

@mikeytown2: This seems like a complex issue. Can you please help isolate the problem by providing an export of your rule, describing your setup (php version, mysql, apache version, etc), and further test from a clean Drupal site to see at what exact point this error occurs?

mikeytown2’s picture

PHP 5.2.5
mySQL 5.0.18
Apache 1.3.33
Shared Godaddy hosting

Exported Rule

array (
  'rules' => 
  array (
    'rules_4' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_node_insert',
      '#label' => 'Re-save New Content - Tokens',
      '#active' => 1,
      '#weight' => '0',
      '#status' => 'custom',
      '#conditions' => 
      array (
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'module' => 'Node',
            'base' => 'rules_action_save_variable',
            'label' => 'Save a content',
            'arguments' => 
            array (
              'var_name' => 
              array (
                'type' => 'value',
                'default value' => 'node',
              ),
              'node' => 
              array (
                'type' => 'node',
                'label' => 'Content',
              ),
            ),
          ),
          '#name' => 'rules_save_var_node',
          '#settings' => 
          array (
            '#argument map' => 
            array (
              'node' => 'node',
            ),
          ),
          '#type' => 'action',
        ),
      ),
    ),
  ),
  'rule_sets' => 
  array (
  ),
)

More info on the error from the xmlsitemap maintainer
http://drupal.org/node/270777#comment-1519816

How to replicate error.
Install one of the 3 modules below
http://drupal.org/project/search_block - 6.x 1.x dev
http://drupal.org/project/nodereferrer & CCK node reference
http://drupal.org/project/xmlsitemap - 6.x 1.x dev
Have the above rule active
Create a node

avpaderno’s picture

Title: Adjust module weight from 0 » Duplicate entry Errors
Version: 6.x-1.x-dev » 6.x-1.0-rc1
Status: Fixed » Postponed (maintainer needs more info)
Issue tags: -rules 1.0

I imported the rule into the test Drupal site I use on my PC, and saved three different nodes with taxonomy terms created by devel.module.
I didn't get any error messages, and there aren't any errors in the Drupal reports page.

avpaderno’s picture

Title: Duplicate entry Errors » Duplicate entry errors

In the test site I have CCK, Token, XML Sitemap, Rules, and Flag are enabled; the content types of the nodes I saved are the default ones installed together with Drupal (story, and page).

avpaderno’s picture

Did you try changing the event associated with the rule?

mikeytown2’s picture

Here's my test site setup & I can make it throw an error in xmlsitemap
Default 6.10 install
Enabled modules:
Tokens
Token actions
Rules
Rules Administration UI
XML Sitemap
XML Sitemap: Node

Created a rule
Event: Node -> After saving new content
Actions: Node -> Save a content

Create a page and this is the error I get

Duplicate entry '1' for key 'PRIMARY' query: INSERT INTO xmlsitemap_node (nid, changed, previously_changed, comment_ratio, priority_override) VALUES (1, 1240955053, 1240955053, 0, -2) in includes/common.inc on line 3422.
avpaderno’s picture

If this issue would be confirmed (actually it's just a person to report it), it would be related with the use of this module, as XML Sitemap doesn't throw that error when normally saving a node.

It still to see which module causes the error, but it's surely a module that is causing some hook implementation to be called twice; in the case of XML Sitemap, it seems that hook_nodeapi() is invoked once more.

fago’s picture

Status: Postponed (maintainer needs more info) » Active

oh, I see what the problem is. It occurs when a module reacts on node-insert and saves the fresh node. So any modules that come later on nodeapi-insert would receive first an update and then the initial insert.

--> Node Creation
--> Nodeapi Insert

--> Rule reacts and saves node
--> Node update
--> Nodeapi update

--> Nodeapi Insert end

We could resolve the issue by increasing the module weight of rules, so it comes (hopefully) after most of the modules.

mitchell’s picture

Status: Active » Closed (duplicate)
fago’s picture

Version: 6.x-1.0-rc1 » 6.x-1.x-dev
Status: Closed (duplicate) » Active
Issue tags: +rules 1.0

Indeed #362616: Rules module weight of 0 leads to problems is related, but I prefer to keep this one - so people getting this errors can find it. I think we should increase the module weight. Any suggestions which value would be good?

avpaderno’s picture

The value of the weight for Rules depends on the maximum weight adopted from the other modules; for this reason it's not an immutable value.
I would try with 20, to start; it's big enough to be used without any changes for long time, I think.

Could not the weight of the module be dynamically changed? In that way, if some future modules will use a higher weight, the module is able to adapt itself to the environment conditions (it seems like the module is getting alive ;-)).

mitchell’s picture

Title: Duplicate entry errors » Adjust module weight from 0

+1 for starting with 20
+1 for cognitive reasoning later

:-)

fago’s picture

Status: Active » Fixed

ok, I've set it to 20.

Status: Fixed » Closed (fixed)

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

AlexisWilke’s picture

Status: Closed (fixed) » Fixed

Note that there is a module that uses 99 because (it thinks) it has to be executed last. FYI, it is called jquery_update.

That cognitive reasoning would break everything!

Just wanted to let you know.

I do not know of a good way to handle module order because there can always be a module that thinks it has to be loaded last...

Thank you.
Alexis

Title: Duplicate entry Errors » Adjust module weight from 0
Version: 6.x-1.0-rc1 » 6.x-1.x-dev
Status: Postponed (maintainer needs more info) » Closed (fixed)

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