fix(api): skip uuidv7() creation when PostgreSQL 18 provides it natively#36998
Open
zeeshan56656 wants to merge 1 commit into
Open
fix(api): skip uuidv7() creation when PostgreSQL 18 provides it natively#36998zeeshan56656 wants to merge 1 commit into
zeeshan56656 wants to merge 1 commit into
Conversation
PostgreSQL 18 ships a native pg_catalog.uuidv7(), so the migration's CREATE FUNCTION uuidv7() collided with the built-in and the unqualified COMMENT became ambiguous, aborting the migration on a fresh start. Probe pg_catalog before creating our own uuidv7() and skip it when the server already provides one. uuidv7_boundary(timestamptz) is still created unconditionally since PostgreSQL 18 does not provide it. The downgrade now uses IF EXISTS public-scoped drops so a rollback is a no-op on PostgreSQL 18 and never touches the built-in. Fixes langgenius#36907
Contributor
Pyrefly Type Coverage
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-06-03 08:57:36.151536845 +0000
+++ /tmp/pyrefly_pr.txt 2026-06-03 08:57:22.276500510 +0000
@@ -6103,6 +6103,10 @@
--> tests/unit_tests/libs/test_time_parser.py:54:38
ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account | None` in function `libs.helper.TokenManager.generate_token` [bad-argument-type]
--> tests/unit_tests/libs/test_token_manager.py:76:17
+ERROR Argument `ModuleSpec | None` is not assignable to parameter `spec` with type `ModuleSpec` in function `_frozen_importlib.module_from_spec` [bad-argument-type]
+ --> tests/unit_tests/migrations/test_uuidv7_pg18_migration.py:31:46
+ERROR Object of class `NoneType` has no attribute `loader` [missing-attribute]
+ --> tests/unit_tests/migrations/test_uuidv7_pg18_migration.py:32:5
ERROR TypedDict `TenantCustomConfigDict` does not have key `feature1` [bad-typed-dict-key]
--> tests/unit_tests/models/test_account_models.py:551:23
ERROR TypedDict `TenantCustomConfigDict` does not have key `feature2` [bad-typed-dict-key]
|
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.
Summary
On PostgreSQL 18 a fresh start fails during database migration. Revision
1c9ba48be8e4runsCREATE FUNCTION uuidv7(), but PostgreSQL 18 already ships a nativepg_catalog.uuidv7(). Our create collides with the built-in, and the unqualifiedCOMMENT ON FUNCTION uuidv7that follows becomes ambiguous, so the migration aborts and the API container never finishes booting. Reported against PostgreSQL 18.3 in #36907.This PR guards the create. In
upgrade()we look uppg_proc/pg_namespacefor auuidv7function in thepg_catalogschema before creating our own. When the server already provides one (PostgreSQL 18), we skip both theCREATE FUNCTION uuidv7()and itsCOMMENT, and call sites that useuuidv7()then resolve to the native implementation, which has a compatible zero-argument signature. Theuuidv7_boundary(timestamptz)helper is still created unconditionally because PostgreSQL 18 does not provide it. This reuses the same_is_pg(conn)dialect-guard style that #28188 added to this file.downgrade()now usesDROP FUNCTION IF EXISTS public.uuidv7()andDROP FUNCTION IF EXISTS public.uuidv7_boundary(timestamptz). TheIF EXISTSplus the explicitpublicschema make a rollback a no-op on PostgreSQL 18 (where the public copy was never created) and keep it from ever touching the built-in.Behavior on PostgreSQL 13 to 17 is unchanged: there is no native
uuidv7, so both functions are created exactly as before. The change is scoped to this one migration file.Fixes #36907
Tests
Added
api/tests/unit_tests/migrations/test_uuidv7_pg18_migration.py. It mocks the Alembic bind and covers each branch separately:uuidv7absent (PostgreSQL 13 to 17): bothuuidv7()anduuidv7_boundary()are createduuidv7present (PostgreSQL 18):uuidv7()is skipped,uuidv7_boundary()is still created, and the probe queries thepg_catalogschemadowngrade()emits theIF EXISTSpublic-scoped dropsupgrade()anddowngrade()5 passed.
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods