When removing a file from an entity then uploading one with exactly the same name the following error is produced when trying to save the entity:
The website encountered an unexpected error. Please try again later.
Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'SomeHash' for key 'hash': INSERT INTO {redirect}...
Filefield Paths generates a hash for each redirect it creates and uses it to check if the redirect already exists. Currently Filefield Paths generates this hash using the target or destination path, while the Redirect module uses the source path with the leading slash removed.
This results in Filefield Paths never finding the existing redirect and trying to create a new one.
To resolve this, the module needs to generate a hash the same way as Redirect does. See Drupal\redirect\Entity\Redirect.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | incorrect_redirect_hash_generated-3045063-7.patch | 836 bytes | w.drupal |
| #6 | incorrect_redirect_hash_generated-3045063-6.patch | 696 bytes | w.drupal |
| #2 | incorrect_redirect_hash_generated-3045063-2.patch | 623 bytes | imclean |
Comments
Comment #2
imclean commentedAdded a space.
Comment #3
imclean commentedComment #4
imclean commentedComment #5
brooke_heaton commentedTested #2 - working well for me.
I came across this issue when running Behat tests to create File Media entities - I use the same source file in my tests. The patch resolves the duplicate hash issue.
Comment #6
w.drupal commentedPatch re-rolled to be consistent with the last dev version
Comment #7
w.drupal commentedAlso the language was not taken into account
Comment #8
chrisckTested patch #7 and it works well on D9.1
Comment #9
chrisckSetting to RTBC.
Comment #10
volegerNeed to add tests for that case
Comment #11
junaidpv#7 works.
Comment #12
imclean commentedThis looks like an unrelated change so should probably be a separate issue.
Comment #13
nicklasmf commentedI have an issue where this duplicated hash happens when trying to upload a file multiple times to different directories using Media Library.
Patch #7 works for me as well.