Skip to content

fix: correct publication import ID regenerated before name is set - #1

Open
brtkwr wants to merge 1 commit into
niklasdohmen:add-publication-schemasfrom
brtkwr:fix/publication-import-id
Open

fix: correct publication import ID regenerated before name is set#1
brtkwr wants to merge 1 commit into
niklasdohmen:add-publication-schemasfrom
brtkwr:fix/publication-import-id

Conversation

@brtkwr

@brtkwr brtkwr commented Jul 14, 2026

Copy link
Copy Markdown

Stacked on top of your add-publication-schemas branch (base is your branch, not main), so this diff is just the delta: a one-line fix plus an import test.

The bug

The postgresql_publication resource has a latent import bug (pre-existing on main, inherited by this branch): in resourcePostgreSQLPublicationReadImpl the ID is regenerated from the name attribute before that attribute is written to state, so on import generatePublicationID reads an empty name and produces a malformed "<database>." ID. It breaks ImportStateVerify round-trips.

The change

  • resource_postgresql_publication.go: move d.Set(pubNameAttr, PublicationName) above d.SetId(generatePublicationID(d, database)) so the name is in state before the ID is regenerated (with a short why comment).
  • resource_postgresql_publication_test.go: add an ImportState / ImportStateVerify step to your TestAccPostgresqlPublication_Schemas test. Schema-scoped publications are the newest thing people will import, so it is the natural place to cover it.

Why here

The fix is orthogonal to your schemas feature, but it bites hardest there, and your test was the natural home for the import coverage. I reproduced the failure on your branch before the fix and confirmed green after:

  • Without the reorder (import step only): fails on live PG15 with resource with ID tf_tests_db_<suffix>. not found (note the trailing dot, empty publication name).
  • With the fix: full TestAccPostgresqlPublication suite on live PG15 (docker-compose harness, PGVERSION=15) passes 15, skips 2 (pre-11 truncate variants), 0 failures, including all five of your schema tests and the new import step.
  • gofmt clean, go build ./... and go vet ./postgresql/ pass.

Context: I had independently opened cyrilgdn#653 for the same schemas feature and carry this same fix there. Yours is further along, so I would rather help this one land than duplicate it. Whichever merges first, the other rebases cleanly. Happy to adjust anything.

resourcePostgreSQLPublicationReadImpl regenerated the resource ID from
the name attribute before setting it, so importing a publication
produced a mangled 'database.' ID with an empty publication name.

Set the name attribute first, then regenerate the ID, and add an
ImportStateVerify step to the schemas acceptance test to cover the
import round-trip.
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