User Action that Causes Error

User edits an existing Node (Basic Page type in this case, with a Menu entry), and changes its Title and the Menu Link name (in this case, renaming “Past Events” to “Prior Events”), then tries to Save it.

Expected Result

The Node correctly saves, with a newly generated Path that matches the newly changed Title.

Actual results

On attempt to Save, the editing user sees this: “The website encountered an unexpected error. Please try again later.” The Node is not saved.

The following Error-level entry is placed in the Log, twice (once as a “node” Type and once as a “php” Type):
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'sdY09RdI-vDU64jykErhp5zIE0oJKF6ipzhqtWYLUps' for key 'hash': 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] => sdY09RdI-vDU64jykErhp5zIE0oJKF6ipzhqtWYLUps [:db_insert_placeholder_1] => redirect [:db_insert_placeholder_2] => 73 [:db_insert_placeholder_3] => content/past-events [:db_insert_placeholder_4] => a:0:{} [:db_insert_placeholder_5] => node/126 [: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 6884 of /[censored]/includes/common.inc).

The specific hash value, of course, can vary.

I manually checked the database “{redirect}” table to verify that that hash does indeed exist, and it pointed to the correct node but had the old path in the “source” column. The other fields of that record did not seem to be corrupted in any humanly noticeable way.

Workaround

Click “Search Engfine Optimization (SEO)” near the bottom of the Edit Node page, un-check “Generate automatic URL alias” and manually re-set the “URL alias” to the existing value (in this case, “content/past-events”).

The Save now works, and the Title and Menu entry are appropriately changed, but the path is still based on the old title, which, while it works okay, will mess up SEO.

Additional Workaround Failure

While leaving “Generate automatic URL alias” un-checked, attempted to manually change “URL alias” to the desired new path (“content/prior-events”), clicked “Save,” and then the error came back and so did the two Log entries.

Further Thoughts

  • Since this happens any time the path is altered, even with “Generate automatic URL alias” un-checked and the “URL alias” manually altered, this may not be Pathauto’s fault, but perhaps some Core issue or some other Module interfering. If so, please move it to the appropriate Issue queue. Thanks.
  • According to the SQL statement in the Log Message, this is happening because of an “INSERT INTO {redirect}” when a record with that same `hash` already exists, resulting in a Duplicate Key. When Editing an existing Node, should this not be an UPDATE {redirect} SET … WHERE hash = '…' LIMIT 1”? Or is it supposed to normally “DELETE FROM {redirect} … WHERE hash = '…' LIMIT 1” followed by the INSERT? Or maybe a REPLACE on those databases that support it? Or an “INSERT INTO … ON DUPLICATE KEY UPDATE…” on those databases that support that?
  • Why is the `source` column being set (via :db_insert_placeholder_3) to 'content/past-events' which is the already existing value, not the desired new value (which would be 'content/prior-events')?
  • Are there any other table besides {redirect} where the URL aliases for Nodes are stored? If I wanted to change this manually in the database, what other Tables would I need to update to match lest I wreck the integrity of the database? Or is the `hash` value generated from the new path itself, and so is not something that a human could easily change manually without messing things up?

Comments

mjcarter’s picture

Project: Redirect » Pathauto
Version: 7.x-1.x-dev » 7.x-1.0
Status: Closed (duplicate) » Active

Experiencing the same issue.

Edit: I had changed my URL alias patterns and not deleted the aliases previously generated by the old patterns and bulk updated afterwards. I did this and things seem to be working properly again. Will come back if more issues crop up.

dave reid’s picture

Project: Pathauto » Redirect
Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Postponed (maintainer needs more info)

Please update to the latest Redirect 7.x-1.x. We should have added protection to prevent this from happening.

dave reid’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Tell your client to tell you to check if bugs are fixed in the latest release (beta4) first. This is a duplicate of #1174594: PDO error if user cannot edit paths.

mjcarter’s picture

Project: Pathauto » Redirect
Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Closed (duplicate)

Good call Dave :) , thanks for the help!