Skip to content

direct: Fix phantom diffs from depends_on reordering in job tasks#4990

Open
denik wants to merge 12 commits intomainfrom
denik/jobs-depends-on
Open

direct: Fix phantom diffs from depends_on reordering in job tasks#4990
denik wants to merge 12 commits intomainfrom
denik/jobs-depends-on

Conversation

@denik
Copy link
Copy Markdown
Contributor

@denik denik commented Apr 16, 2026

Changes

Fix phantom diffs in bundle plan caused by the Jobs API returning depends_on arrays in a different order than submitted. Both tasks[*].depends_on and tasks[*].for_each_task.task.depends_on are handled.

Why

After a deploy with the direct engine, every subsequent bundle plan showed spurious depends_on updates even though nothing changed, creating a perpetual deploy-plan-update cycle.

Tests

  • Unit tests for nested depends_on keyed-slice diffing (reorder, field change, add, remove).
  • Testserver sorts depends_on by task_key to simulate real API reordering.
  • Acceptance test (depends-on-reorder, direct-only) verifies deploy followed by plan reports no changes.

denik added a commit that referenced this pull request Apr 16, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

Approval status: pending

/acceptance/bundle/ - needs approval

6 files changed
Suggested: @andrewnester
Also eligible: @pietern, @shreyas-goenka, @lennartkats-db, @anton-107, @janniklasrose

/bundle/ - needs approval

Files: bundle/direct/dresources/job.go
Suggested: @andrewnester
Also eligible: @pietern, @shreyas-goenka, @lennartkats-db, @anton-107, @janniklasrose

General files (require maintainer)

4 files changed
Based on git history:

  • @andrewnester -- recent work in ./, libs/structs/structdiff/, acceptance/bundle/invariant/configs/

Any maintainer (@andrewnester, @anton-107, @pietern, @shreyas-goenka, @simonfaltum, @renaudhartert-db) can approve all areas.
See OWNERS for ownership rules.

denik added 12 commits April 16, 2026 15:32
Register tasks[*].depends_on and tasks[*].for_each_task.task.depends_on
as keyed slices so task dependencies are diffed by task_key rather than
by position.

Also fix pathToPattern in structdiff to treat key-value path nodes as [*]
wildcards, enabling nested keyed-slice patterns to match correctly.

Co-authored-by: Isaac
Test that reordered depends_on arrays within job tasks produce no
phantom diffs when using the tasks[*].depends_on key function.

Task: 001.md

Co-authored-by: Isaac
Simulates real API behavior where depends_on entries are returned in a
different order than submitted. Adds an acceptance test that verifies
bundle plan shows 0 changes after deploy despite the reordering.
The depends_on reordering fix is in the direct engine. The terraform
engine handles ordering through its provider, so the acceptance test
should only run with the direct engine.

Task: 001.md

Co-authored-by: Isaac
Adds a template config with tasks that use depends_on to verify
depends_on handling is stable across deploy/redeploy cycles.
Remove the dedicated acceptance/bundle/resources/jobs/depends-on-reorder/
test since the invariant test config job_with_depends_on.yml.tmpl covers
the same scenario through the no_drift and continue_293 variants.

Exclude job_with_depends_on from the migrate variant because terraform
does not apply keyed-slice ordering for depends_on.

Task: 002.md

Co-authored-by: Isaac
Remove the EnvMatrixExclude for job_with_depends_on.yml.tmpl from the
migration invariant test. Instead, pass --noplancheck to the migrate
command for this config, since Terraform's plan detects false drift
due to depends_on ordering differences.

The post-migration plan check (using direct engine) validates no drift
correctly because the direct engine handles keyed-slice ordering.

Task: 003.md

Co-authored-by: Isaac
The terraform provider sorts depends_on entries by task_key on Read
(see terraform-provider-databricks PR #3000). Since depends_on uses
TypeList (order-sensitive), terraform plan detects positional differences
when the config order doesn't match the sorted state order. Fix by sorting
depends_on in the CLI's terraform conversion, matching the provider's behavior.

This removes the --noplancheck workaround from the migration invariant test.

Task: 004.md
Remove the sortDependsOn function and its usage in convertJobResource.
The terraform provider already sorts depends_on by task_key on Read,
so fixing the ordering in the CLI is unnecessary complexity.

Instead, restore --noplancheck for job_with_depends_on in the migrate
invariant test with a detailed comment explaining the false drift:
the provider sorts depends_on by task_key using TypeList (order-sensitive),
so terraform plan reports positional differences when the config order
doesn't match the sorted state.

Task: 005.md

Co-authored-by: Isaac
@denik denik force-pushed the denik/jobs-depends-on branch from d91cd1b to ef3cfc8 Compare April 16, 2026 15:45
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