Skip to content

fix(BA-6899): stop app_configs downgrade from creating its enum twice#12887

Merged
jopemachine merged 2 commits into
mainfrom
fix/BA-6899-app-configs-downgrade-duplicate-enum
Jul 20, 2026
Merged

fix(BA-6899): stop app_configs downgrade from creating its enum twice#12887
jopemachine merged 2 commits into
mainfrom
fix/BA-6899-app-configs-downgrade-duplicate-enum

Conversation

@jopemachine

Copy link
Copy Markdown
Member

Problem

84d5c6daf8cc's downgrade() fails every time, on every database. Any downgrade that has to cross this revision is blocked.

It creates app_config_scope_type twice within itself:

app_config_scope_type = sa.Enum("DOMAIN", "PROJECT", "USER", name="app_config_scope_type")
app_config_scope_type.create(op.get_bind(), checkfirst=True)   # 1. creates it
op.create_table(
    "app_configs",
    ...
    sa.Column("scope_type", app_config_scope_type, ...),       # 2. emits CREATE TYPE again

upgrade() drops the type, so at this point it is absent and step 1 creates it. Step 2 then re-emits CREATE TYPE for the same enum with no existence check:

asyncpg.exceptions.DuplicateObjectError: type "app_config_scope_type" already exists
[SQL: CREATE TYPE app_config_scope_type AS ENUM ('DOMAIN', 'PROJECT', 'USER')]

This is not environment-specific and not an artifact of the one-shot bootstrap. On a clean DB built at head, with the enum confirmed absent (ABSENT at head) and no model declaring it, stamping 84d5c6daf8cc and running only its downgrade reproduces the failure deterministically.

Fix

Delete the explicit create() and let create_table() create the type once. upgrade() already does DROP TYPE IF EXISTS, so the pair round-trips.

Verification

Run against a real DB built at head, before and after:

step before after
downgrade 84d5c6daf8cc -> f3a8c1d05e64 DuplicateObjectError exit 0 — app_configs restored, enum present, scope_type is USER-DEFINED/app_config_scope_type
upgrade back to 84d5c6daf8cc exit 0 — table and enum dropped again
downgrade a second time exit 0

Found while verifying the downgrade chain for #12881.

🤖 Generated with Claude Code

The downgrade created app_config_scope_type twice within itself: once
explicitly via create(checkfirst=True), and again implicitly when
create_table() emitted CREATE TYPE for the column typed by that same
Enum. The implicit one carries no existence check, so the downgrade
aborted with DuplicateObjectError every time, blocking any downgrade
that has to cross this revision.

Drop the explicit create() and let create_table() create the type once.
upgrade() already drops the type with DROP TYPE IF EXISTS, so the pair
round-trips.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the size:XS ~10 LoC label Jul 15, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the comp:manager Related to Manager component label Jul 15, 2026
@github-actions github-actions Bot added the require:db-migration Automatically set when alembic migrations are added or updated label Jul 15, 2026
@jopemachine
jopemachine marked this pull request as ready for review July 16, 2026 10:37
@jopemachine
jopemachine requested a review from a team as a code owner July 16, 2026 10:37
Copilot AI review requested due to automatic review settings July 16, 2026 10:37
@jopemachine jopemachine added this to the 26.4 milestone Jul 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the legacy app_configs migration downgrade by preventing duplicate PostgreSQL enum creation.

Changes:

  • Lets op.create_table() create app_config_scope_type.
  • Adds a changelog fragment for the downgrade fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
84d5c6daf8cc_drop_legacy_app_configs_table.py Removes redundant enum creation.
changes/12887.fix.md Documents the migration fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fregataa fregataa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how duplicate error happens. It seems upgrade should drop the app config scope enum type properly

@jopemachine

Copy link
Copy Markdown
Member Author

I don't understand how duplicate error happens. It seems upgrade should drop the app config scope enum type properly

It's not that the enum wasn't removed during the upgrade. The issue is that the downgrade attempts to create the enum a second time. As a result, the downgrade fails even when the enum doesn't exist. @fregataa

@jopemachine
jopemachine merged commit b908663 into main Jul 20, 2026
37 checks passed
@jopemachine
jopemachine deleted the fix/BA-6899-app-configs-downgrade-duplicate-enum branch July 20, 2026 02:40
jopemachine added a commit that referenced this pull request Jul 20, 2026
…#12887) (#12966)

Co-authored-by: Gyubong Lee <gbl@lablup.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component require:db-migration Automatically set when alembic migrations are added or updated size:XS ~10 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants