Skip to content

fix: handle non-English PostgreSQL error messages in create_publication_result#4685

Open
gilyazovigor wants to merge 1 commit into
electric-sql:mainfrom
gilyazovigor:fix/check-publication-exists-before-create
Open

fix: handle non-English PostgreSQL error messages in create_publication_result#4685
gilyazovigor wants to merge 1 commit into
electric-sql:mainfrom
gilyazovigor:fix/check-publication-exists-before-create

Conversation

@gilyazovigor

@gilyazovigor gilyazovigor commented Jul 3, 2026

Copy link
Copy Markdown

Problem

When PostgreSQL is configured with a non-English locale (e.g. Russian), error messages
are returned in that locale. The create_publication_result function matches the error
message 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant