Repository navigation
feat(api): introduce model-type migration script - #36520
Merged
wylswz merged 14 commits intoMay 27, 2026
Merged
Conversation
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-05-26 16:04:32.206371986 +0000
+++ /tmp/pyrefly_pr.txt 2026-05-26 16:04:22.491274000 +0000
@@ -592,6 +592,14 @@
--> tasks/regenerate_summary_index_task.py:277:60
ERROR Class member `AsyncWorkflowCFSPlanScheduler.plan` overrides parent class `CFSPlanScheduler` in an inconsistent manner [bad-override-mutable-attribute]
--> tasks/workflow_cfs_scheduler/cfs_scheduler.py:19:5
+ERROR Object of class `FromClause` has no attribute `metadata` [missing-attribute]
+ --> tests/helpers/legacy_model_type_migration.py:64:16
+ERROR Object of class `FromClause` has no attribute `metadata` [missing-attribute]
+ --> tests/helpers/legacy_model_type_migration.py:80:16
+ERROR Argument `dict[_KeyType, Any]` is not assignable to parameter `object` with type `dict[str, object]` in function `list.append` [bad-argument-type]
+ --> tests/helpers/legacy_model_type_migration.py:138:23
+ERROR Object of class `FromClause` has no attribute `insert` [missing-attribute]
+ --> tests/helpers/legacy_model_type_migration.py:182:13
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/integration_tests/controllers/openapi/conftest.py:35:43
ERROR Argument `Literal['owner']` is not assignable to parameter `role` with type `SQLCoreOperations[TenantAccountRole] | TenantAccountRole` in function `models.account.TenantAccountJoin.__init__` [bad-argument-type]
@@ -1976,6 +1984,30 @@
--> tests/unit_tests/commands/test_clean_expired_messages.py:94:9
ERROR Expected a callable, got `None` [not-callable]
--> tests/unit_tests/commands/test_clean_expired_messages.py:176:9
+ERROR Generator function should return `Generator` [bad-return]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:36:38
+ERROR Object of class `FromClause` has no attribute `insert` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:204:13
+ERROR Object of class `object` has no attribute `callback` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:383:5
+ERROR Object of class `object` has no attribute `callback` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:444:5
+ERROR Object of class `TextIOBase` has no attribute `name` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:457:17
+ERROR Class `object` has no class attribute `__table__` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:541:48
+ERROR Class `object` has no class attribute `__table__` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:620:48
+ERROR Class `object` has no class attribute `__table__` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:723:48
+ERROR Class `object` has no class attribute `__table__` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:801:48
+ERROR Class `object` has no class attribute `__table__` [missing-attribute]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:856:42
+ERROR Argument `object` is not assignable to parameter `orig` with type `BaseException` in function `sqlalchemy.exc.DBAPIError.__init__` [bad-argument-type]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:1226:44
+ERROR Argument `SimpleNamespace` is not assignable to parameter `orig` with type `BaseException` in function `sqlalchemy.exc.DBAPIError.__init__` [bad-argument-type]
+ --> tests/unit_tests/commands/test_legacy_model_type_migration.py:1250:57
ERROR Expected a callable, got `None` [not-callable]
--> tests/unit_tests/commands/test_reset_encrypt_key_pair.py:18:9
ERROR Object of class `ModuleType` has no attribute `upgrade` [missing-attribute]
|
Contributor
Pyrefly Type Coverage
|
QuantumGhost
force-pushed
the
feat/model-type-migration-script
branch
from
May 26, 2026 01:25
8d0ad9d to
1a25acc
Compare
QuantumGhost
marked this pull request as ready for review
May 26, 2026 01:26
wylswz
previously approved these changes
May 26, 2026
GareArc
previously approved these changes
May 26, 2026
GareArc
enabled auto-merge
May 26, 2026 04:13
wylswz
previously approved these changes
May 26, 2026
QuantumGhost
marked this pull request as draft
May 26, 2026 06:26
QuantumGhost
force-pushed
the
feat/model-type-migration-script
branch
from
May 26, 2026 06:26
fbdfee2 to
ee8d69c
Compare
QuantumGhost
marked this pull request as ready for review
May 26, 2026 07:26
QuantumGhost
force-pushed
the
feat/model-type-migration-script
branch
from
May 26, 2026 16:03
6ee5a35 to
1a9fdef
Compare
hjlarry
approved these changes
May 27, 2026
GareArc
approved these changes
May 27, 2026
wylswz
enabled auto-merge
May 27, 2026 02:09
wylswz
approved these changes
May 27, 2026
1 task done
6 tasks done
wylswz
pushed a commit
that referenced
this pull request
May 27, 2026
This was referenced Jul 3, 2026
OpenAI-API-compatible provider keeps broken Perplexity Sonar credentials and validation fails
#36386
Closed
This was referenced Jul 3, 2026
Closed
6 tasks done
Ssazurov
pushed a commit
to Ssazurov/dify
that referenced
this pull request
Aug 8, 2026
6 tasks done
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.
AI disclosure: This PR was primarily drafted with Codex using GPT-5.4. I have reviewed and edited the final diff, and I am responsible for the content.
This PR adopts a relatively verbose style intentionally, so that the script can be reviewed carefully and any issues can be spotted easily.
Please review this PR with extra care: it modifies production credential records. Any script errors could cause data loss or a major outage.
Summary
This migration normalizes legacy provider-related
model_typevalues to the canonical enum values:text-generation->llmembeddings->text-embeddingreranking->rerankThe main goal is not just to update enum values in place, but to do so safely when a legacy row and a canonical row would collapse onto the same logical key after normalization.
How conflicts are handled
For each table, the migration groups rows by the normalized business key (that is, the key after mapping legacy
model_typevalues to their canonical value). If multiple rows end up in the same logical group:model_typeto the canonical value if neededThe winner is chosen deterministically as the most recently updated row (
updated_at), withidas the tiebreaker.This is how the migration avoids creating unique-key or logical-key conflicts during canonicalization.
Table-specific rules
provider_modelsRows are grouped by the logical key behind
unique_provider_model_name:(tenant_id, provider_name, model_name, model_type)If legacy and canonical rows collide after normalization, they are merged into one winner row.
tenant_default_modelsRows are grouped by the logical key behind
unique_tenant_default_model_type:(tenant_id, model_type)Again, legacy/canonical duplicates are merged before final canonicalization.
provider_model_settingsThis table does not enforce the key at the DB level, but the migration treats the following as the logical uniqueness boundary:
(tenant_id, provider_name, model_name, model_type)So duplicates are merged the same way as the indexed tables.
provider_model_credentialsThis table also uses a logical uniqueness rule rather than relying on a DB unique index:
(tenant_id, provider_name, model_name, credential_name, model_type)When duplicates are merged, the migration also rewrites references from loser credentials to the winner credential in:
provider_modelsload_balancing_model_configsOnly after references are rewritten are loser credential rows removed.
load_balancing_model_configsThis table is handled differently.
For normal rows, canonicalization is mostly row-by-row.
For
name="__inherit__"rows, the migration first performs a pre-deduplication step by normalized business key:(tenant_id, provider_name, model_name, model_type)This is necessary because a legacy
__inherit__row and a canonical__inherit__row could otherwise collide after themodel_typeupdate. The migration resolves that duplicate first, then canonicalizes remaining rows.Operational behavior
--applyis required to persist changes--outputflag to capture a complete log of migration changes and execution context for debugging or recovery.Because this migration updates and deletes a large volume of data, we strongly recommend that you:
Continuation of #36427.
Closes #36426 #36129 #36386
Screenshots
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods