Hi, when I generate redirects sometimes get an error message:
An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=111&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5Unw3RhlsfSgQIv1tvrY2ajsov3Dsm9KswXYQ-0XNMg' 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] => 5Unw3RhlsfSgQIv1tvrY2ajsov3Dsm9KswXYQ-0XNMg [:db_insert_placeholder_1] => redirect [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => clothu [:db_insert_placeholder_4] => a:0:{} [:db_insert_placeholder_5] => node/117 [: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 7136 of /home/quickstart/websites/drupal.dev/includes/common.inc).
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | redirect-duplicate_redirect_save_handling-2260499-11.patch | 804 bytes | mrmikedewolf |
Comments
Comment #1
zestagio commentedComment #2
zestagio commentedComment #3
zestagio commentedComment #4
pere orgaHmm, I understand that this patch fixes your problem but, how can this occur?
Could you give us some steps of how to reproduce the problem you are experiencing? I've never seen it.
Comment #5
zestagio commentedThis error occurs very rarely. What would you reproduce it with a high probability, it is necessary to generate a large number of nodes (> 500) with a module devel
Comment #6
zestagio commentedAlso for the greater likelihood of reproducing the bug, you can generate a large number of redirects using devel
Comment #7
pere orgaok
Comment #8
pere orgaComment #9
mrmikedewolf commentedGood patch. I've just renamed it to follow drupal.org conventions. Please credit original author for the content.
Comment #10
mrmikedewolf commentedActually, I double back. I needed to make an additional modification to avoid the error. With the existing patch, if a duplicate hash exists, the query is switched from an insert query to an update query, which is correct, but I still get the Integrity constraint because when it saves, it does so with a new rid. What actually needs to happen is if there is an existing redirect that matches the new one, it should be updated. So the rid of the existing redirect needs to be added to the new one.
Comment #11
mrmikedewolf commentedHere is my patch.
Comment #12
jami commentedI was running into this problem at around row 400-500 of 1800 nodes I was adding redirects to. With the patch in 11 applied, it works perfectly. Thank you!
My code, in case it helps explain why this happens:
Comment #13
rp7 commented#11 fixed this for me. Thanks!
Comment #14
rkeppner commented#11 also worked for me.
Comment #15
kevinwal commentedHi rkeppner! :)
I have the same in D8. Any insight to where that is in the D8 version?
Comment #16
pifagor commentedComment #17
pifagor commentedRTBC
Comment #18
davemybes commentedSee https://www.drupal.org/project/redirect/issues/2887866 for Drupal 8 issue.
Comment #19
pifagor commentedComment #22
pifagor commentedComment #24
jummonk commentedI encounter the same issue. It happens actually do an update of a node with multiple redirects with the same source and language. The redirect_hash module can give the hash of the other redirect which leads to an update with the correct rid but the hash from another redirect => integritey constraint violation. This should be solved by redirect_hash taking the rid also into account to calculate the hash. What I still don't get is how the initial situation is possible. (The multiple redirects with same source and language and different hashes.)