There's a whole bunch of bugs caused by 'duplicate key' errors http://goo.gl/f9YdV
Coming from #505812: PDO uses inconsistant error codes between DBs
There's a 2 approaches in core introduced in #364348: OpenID throws an error when two accounts try to use the same OpenID
1) check existence by key in form validation level - most of core uses this
2) try...catch with exception handling in API level (_save)
First one could lead to some drift in multi-db config (master-slave replication)
Second has no consistency in constraint violation detection
I think we should use second approach and unify this all over core
Comment | File | Size | Author |
---|---|---|---|
#25 | integrity-constraint-violation-11.patch | 6.82 KB | c960657 |
#23 | integrity-constraint-violation-10.patch | 6.21 KB | c960657 |
#19 | integrity-constraint-violation-9.patch | 6.96 KB | c960657 |
#14 | integrity-constraint-violation-8.patch | 6.98 KB | c960657 |
#12 | integrity-constraint-violation-7.patch | 10 KB | c960657 |
Comments
Comment #1
c960657 CreditAttribution: c960657 commentedTrue. Even in a single-db setup it would not be bullet-proof unless access to the table was restricted by semaphores.
I agree. I suggest we create a separate exception class for all 23xxx Integrity Constraint Violation errors.
http://www.postgresql.org/docs/8.1/static/errcodes-appendix.html
Comment #2
c960657 CreditAttribution: c960657 commentedHow about this?
Comment #4
c960657 CreditAttribution: c960657 commentedI couldn't reproduce all the test errors reported by the test bot (it complained about fatal errors in line numbers that were containts the initial "function testFoo()" method declaration). But I fixed one bug in lock.inc that might have caused problems elsewhere.
Comment #5
andypostLooks good, are you sure that all places are fixed?
Comment #6
c960657 CreditAttribution: c960657 commentedI looked through the code (especially places where we catch PDOExceptions) but couldn't find any other places where we should catch the new exception (I wonder why our own database exceptions don't inherit from PDOException? Then changes like this would not break existing code - though of course we should still use the more specific exception class when appropriate).
This updated patch contains an update to the pgsql driver also. This has been tested on Postgres 8.4 (I ran all database tests — two tests were failing with and without the patch). I had to patch core in two places in order to even install Drupal on Postgres?! This is not included in the patch (I assume this problem is being tracked elsewhere, though I couldn't find the ticket).
The patch was also tested successfully with the sqlite driver (I ran all database tests — one test were failing with and without the patch). I fixed a test failure (database_test line 3186, “The whole transaction is rolled back when a duplicate key insert occurs.”) by adding a missing "use Exception" to core/lib/Drupal/Core/Database/Query/Insert.php.
I'm a bit surprised about the problems with the pgsql and sqlite drivers. Don't we have test bots running tests on with engines?
Comment #7
c960657 CreditAttribution: c960657 commentedI created a separate issue for the Postgres install troubles: #1491526: Cannot install Drupal on PostgreSQL
Comment #8
c960657 CreditAttribution: c960657 commentedReroll (needed because of #1477446: Move lock backend to PSR-0 code).
Comment #9
c960657 CreditAttribution: c960657 commentedReroll.
Comment #10
c960657 CreditAttribution: c960657 commentedReroll.
Comment #12
c960657 CreditAttribution: c960657 commentedBad patch.
Comment #13
c960657 CreditAttribution: c960657 commentedComment #14
c960657 CreditAttribution: c960657 commentedBah, the last patch was also bad (it included a fix for some other issue also). This is better, I hope.
Comment #15
mikl CreditAttribution: mikl commentedLooks great, it will make it a lot easier to catch these errors specifically.
Comment #16
Dries CreditAttribution: Dries commentedThis patch needs a re-roll. Asking for a re-test.
Comment #17
Dries CreditAttribution: Dries commented#14: integrity-constraint-violation-8.patch queued for re-testing.
Comment #19
c960657 CreditAttribution: c960657 commentedReroll.
Comment #21
c960657 CreditAttribution: c960657 commented#19: integrity-constraint-violation-9.patch queued for re-testing.
Comment #23
c960657 CreditAttribution: c960657 commentedComment #25
c960657 CreditAttribution: c960657 commentedComment #26
c960657 CreditAttribution: c960657 commentedComment #27
c960657 CreditAttribution: c960657 commentedComment #28
catchNot sure why this is listed as a feature. Committed/pushed to 8.x.
Comment #29
daften CreditAttribution: daften commentedI'm guessing this is nice to have/necessary for drupal7 as well, unless this proves impossible/too big of a task.
Comment #30
c960657 CreditAttribution: c960657 commentedComment #35
alexpottGonna mark this as fixed against 8.x dev because there's been no movement on the 7.x work for 7 years.
Comment #36
alexpott