fix: handle non-English PostgreSQL error messages in create_publication_result#4685
Open
gilyazovigor wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When PostgreSQL is configured with a non-English locale (e.g. Russian), error messages
are returned in that locale. The
create_publication_resultfunction matches the errormessage text with a pin operator (
^error_message) expecting English:%{code: :duplicate_object, pg_code: "42710", message: ^error_message} ->If PostgreSQL returns the message in another language (e.g. "публикация "..." уже существует"),
the pattern does not match and falls through to _ -> raise error, causing Electric to
crash and enter an infinite retry loop.
Fix
Use CREATE PUBLICATION IF NOT EXISTS instead of CREATE PUBLICATION, so the duplicate
publication error never occurs in the first place, making the message text matching irrelevant.
query = "CREATE PUBLICATION IF NOT EXISTS #{Utils.quote_name(state.publication_name)}"
Reproduction
Configure PostgreSQL with a non-English locale (lc_messages set to anything other than en_*)
Start Electric when a publication with the same name already exists
Electric enters an infinite crash loop with the localized duplicate publication error
Notes
This issue was discovered after migrating from PostgreSQL 14 to PostgreSQL 18,
where the existing publication was preserved during migration and Electric failed to start.