Fix some issues with PostgreSQL not running with an english locale#3616
Conversation
rud
left a comment
There was a problem hiding this comment.
That's pretty elegant.
Would it be worth proving this with integration test or is that going too far?
|
@e-tobi the tests are failing, may just be a flaky test. Could you poke at it? |
Such an integration test would require the PostgreSQL server to be started with a different locale. Unfortunately the tests are currently designed to use a fixed external PostgreSQL server. It surely can be done (I'm actually doing this in the unit tests of my application that uses Marten) but I'm not sure, Jeremy would like this. |
To check for exceptions caused by a uniqueness violation, use the SqlError instead of the exception messages, which might be translated to a different locale. Also use the PostgresErrorCodes constants from Npgsql.
Exception messages get translated!
Instead of checking the exception message, check if SqlState equals PostgresErrorCodes.InFailedSqlTransaction ("25P02")
Do not check the full exception messages, if they might be translated to a non-english locale.
Check constraint name instead of exception message and make regex for details extraction more language independent.
...when trying to truncate a non-existing table.
I'm pretty sure the tests are not failing because of the changes in this PR. |
|
The failing tests are unrelated (and most likely my fault for not catching it before) |
Instead of relying on exception messages, use SqlState, because exception messages might be language dependent.