Skip to content

Upgrade fails at service_providers.0095 when Team has columns added by later migrations #5000

Open

Description

@preston-56

Problem

Running migrate across 2026-10-20..2026-10-26 in one step fails at service_providers.0095_auto_model_sync_20261018:

Migration 'notify_deprecated_models' failed: column teams_team.moderation_enabled does not exist

The migration runs notify_deprecated_models, which loads the live Team model. Current code has moderation_enabled, so the query selects it. That column is added by teams.0020_team_moderation_fields, which depends on service_providers.0096 and so always runs after 0095.

Who it affects

Any database with teams using a deprecated model that applies 0095 and teams.0020 in the same migrate run: self-hosted installs upgrading from before 2026-10-20 to after 2026-10-26, and older dev databases. Installs that applied the migrations as they were released, and fresh installs with no teams, are not affected.

The upgrade stops at 0095 on every retry, leaving later migrations unapplied. Faking 0095 gets past it but skips the deprecated-model notifications.

Reproduce

Verified on a scratch database:

  1. migrate an empty database. 0095 passes: "Found 23 deprecated models affecting 0 team(s)".
  2. Add a team with a pipeline node whose llm_provider_model is a deprecated model (azure / gpt-4.1-nano).
  3. Migrate back to service_providers.0094_deprecate_openai_gpt_4_models, faking 0095 since it is irreversible. This unapplies teams.0020, matching an install last updated before 2026-10-20.
  4. migrate: 0095 fails with the error above.

Suggested fix

Load only the fields the command uses: .only("id", "name", "slug") on both Team queries (L50, L64). With that change the steps above pass: 0095 notifies the team and the remaining migrations, including teams.0020, apply. A migration dependency can't fix it, because the existing one is what forces 0095 to run first.

RunDataMigration calls commands against the live models, so any command that loads full rows can break the same way when a later migration adds a column.

Activity

  1. preston-56 commented on Nov 12, 2026

    @preston-56
    ContributorAuthor

    Second form of the same problem, on a fresh database:

    • notify_deprecated_models also reads live Node rows, which selects pipelines_node.archived_with_pipeline (added in pipelines.0036):

      for node in db_model.nodes.select_related("pipeline"):

    • None of its callers (service_providers 0071, 0077, 0085, 0089, 0095) depend on the latest pipelines or teams migrations. A fresh install passes only because migrate reaches the pipelines leaf before service_providers.

    • Any new migration whose dependencies pull service_providers forward breaks a fresh migrate with column pipelines_node.archived_with_pipeline does not exist. Reproduced on a fresh database with an experiments migration that depended on teams.0020; no teams needed, since earlier migrations already create deprecated LlmProviderModel rows.

    • .only("id", "name", "slug") on Team does not cover this query, so the fix needs the Node read narrowed too, or the command made a no-op inside migrations.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions