To replicate issue:

Conditions
the content type is a blog entry (or whatever)

Actions
Load a taxonomy term
And assign it to the content

This works fine if a person has not manually chosen the same taxonomy term already, but if they have it throws an error. This is because both the node form and the Rules actions are trying to insert the same entry.

Likewise, this will also happen if you simply try to Edit the form later and submit (as the taxonomy term will be autofilled in the form).

user warning: Duplicate entry '4-31' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (20, 31, 4) in /Users/username/Sites/whatever/modules/taxonomy/taxonomy.module on line 698.

More validation is needed to prevent this.

Comments

fago’s picture

Component: Rules Core » Rules Engine
Status: Active » Postponed (maintainer needs more info)

Rules does only

$node->taxonomy[$taxonomy_term->tid] = $taxonomy_term;

and then saves the node and that only if term isn't there yet. Thus a simple load and save should be fine? So with which event can reproduce that? Perhaps somehow after the node has been saved after a node edit?

Anonymous’s picture

You can reproduce this with what I posted above.

Actions
Load a taxonomy term
And assign it to the content

Then in your node form, manually add the same taxonomy term that Rules is going to Load and Assign. So the taxonomy term will be submitted via the standard user-entered taxonomy form field and Rules.

OR

Create a node. Save. Edit. Save.

fago’s picture

But where stems the node from? Which event are you using?

webkenny’s picture

Status: Postponed (maintainer needs more info) » Active

@fago, sorry for that. we both are working this issue. The event is "Content is about to be saved".

kevin hankens’s picture

Status: Active » Needs review
StatusFileSize
new889 bytes

The issue is that fixed vocabularies come through in the node object as:

$node->taxonomy[$taxonomy_term->tid]

where tag vocabularies come through as:

$node->taxonomy['tags'][[delta]]

Here is a patch for rules/modules/taxonomy.rules.inc that also checks to see that the term to add is not an existing tag. I hope this helps!

webkenny’s picture

Works for me. Thanks Kevin.

fago’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Status: Needs review » Needs work

I see, however $node->taxonomy['tags'] might not be initialized. I suppose in this case this fix will produce an warning.

micnap’s picture

This fixed it for me. Thanks!

Mickey

fago’s picture

Status: Needs work » Closed (cannot reproduce)

As this bug-report is rather old, please verify it's still valid in the latest dev version and re-open if so. For now, I'm marking it as closed.