As the title says. If someone edits a node title and the redirect tries to change, everything goes boom.

Giving that role "Create and edit path aliases" makes the error go away.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'mSSVKeKuvgeJPJoIn0ubyQk7ao918-ubfeTbCSJxN2I' for key 2: INSERT INTO {redirect} (hash, type, uid, source, source_options, redirect, redirect_options, language, status_code, count, access) 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, :db_insert_placeholder_9, :db_insert_placeholder_10); Array ( [:db_insert_placeholder_0] => mSSVKeKuvgeJPJoIn0ubyQk7ao918-ubfeTbCSJxN2I [:db_insert_placeholder_1] => redirect [:db_insert_placeholder_2] => 8 [:db_insert_placeholder_3] => stories/20110404/miss-r-rules [:db_insert_placeholder_4] => a:0:{} [:db_insert_placeholder_5] => node/56893 [:db_insert_placeholder_6] => a:0:{} [:db_insert_placeholder_7] => und [:db_insert_placeholder_8] => 0 [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 ) in drupal_write_record() (line 6776 of /includes/common.inc).

Comments

dave reid’s picture

Is Workbench Moderation enabled?

agentrickard’s picture

Nope.

We have an internal ticket for this. (3934)

dave reid’s picture

What was the entire change history of the node?

agentrickard’s picture

Title changes:

- Miss R Rules
- Miss RR Rules
- Miss R Rules
- Miss R R Rules

Ad infinitum.

mfer’s picture

I can replicate this problem with the admin user.

Based on the error and some testing there is a duplicate key because of past redirects. For example, a node had a path of "boom". Now, you try to change it to "stick". Redirect would setup a redirect from boom to stick. But, stick was a previous redirect. The hashes (db row key) created are the same as a previous one and thus we get a duplicate key error.

dave reid’s picture

The auto-redirection does not currently check against any existing redirects and it probably should. Also, this could create problems since renaming the title back to 'Miss R Rules' the second time will cause problems as well as we will have both a redirect and an alias wanting to use the path 'miss-r-rules'. Only one shall win (and it'll be redirect.module, which may end up causing an infinite loop).

mfer’s picture

Status: Active » Needs review
StatusFileSize
new1.49 KB

Attached is a patch that checks for the existence of the redirect before saving it. This should stop the duplicate errors.

dave reid’s picture

Status: Needs review » Needs work
+++ b/redirect.moduleundefined
@@ -328,7 +328,10 @@ function redirect_path_update(array $path) {
-    redirect_save($redirect);
+    // Check if the redirect exists before saving.
+    if (!redirect_check_duplicate_by_hash($redirect)) {
+      redirect_save($redirect);
+    }

I don't really see the need for the new function - just doing the following is fine as it doesn't mess up redirect_save() at all.

redirect_hash($redirect);
if (!redirect_loady_by_hash($redirect->hash)) {
  redirect_save($redirect);
}

I'd prefer to keep this workaround simple for now since we may have to revisit it.

Powered by Dreditor.

dave reid’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
mfer’s picture

Status: Needs work » Needs review
StatusFileSize
new557 bytes

And another pass....

The big difference here is that the hash is generated w/o a lot of the same contextual information passed into the hash hooks that's available during the hash generation in the save step.

mfer’s picture

StatusFileSize
new556 bytes

Lets try this again w/o the misspelling.

dave reid’s picture

The additional stuff in redirect_save() is irrelevant to hashing, just to the presave/insert/update hooks, so that's why I prefer the 'simpler' version.

dave reid’s picture

Status: Needs review » Fixed

Committed #11 with an additional quick test to Git: http://drupalcode.org/project/redirect.git/commit/5de9fd4. I'll work later on expanding the test, but for now it does its job of ensuring this fatal error doesn't pop up.

Status: Fixed » Closed (fixed)

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

lsolesen’s picture

I started getting this error a lot after enabling workbench moderation. But only on some nodes.