Skip to content

direct: use the bundle's current user in create recovery instead of calling /Me - #8128

Open
denik wants to merge 1 commit into
mainfrom
direct-created-by-current-user
Open

denik wants to merge 1 commit into
mainfrom
direct-created-by-current-user

Conversation

@denik

@denik denik commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Changes

Unity Catalog create recovery (catalogs, schemas, volumes, external locations, registered models, secrets) now compares created_by with workspace.current_user, which the bundle already resolved, instead of calling CurrentUser.Me on each recovery. Deploy attaches it to the apply context; without it, recovery fails with the original create error rather than take the resource over.

Why

Follow-up to #7910: the deploying user is known before the deploy, so asking the API again is a wasted request on an already failing path.

Tests

The schema recovery tests now fail on any /Me request; new TestSchemaCreateRecoveryRequiresCurrentUser. TestCreateRecoveryCoverage sets the context user; without it the UC resources fail.

This pull request and its description were written by Isaac.

Unity Catalog create recovery called CurrentUser.Me on every recovery to
check created_by, although the bundle already resolved
workspace.current_user before the deploy. Attach that user name to the
apply context and read it there.

Co-authored-by: Isaac <no-reply@databricks.com>
@denik
denik requested review from a team as code owners November 27, 2026 15:13
@github-actions github-actions Bot added the DABs DABs related issues label Nov 27, 2026

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review at dc64414. Each finding was verified against the code.

No blocking issues found. 3 non-blocking comment(s) below.

This PR makes Unity Catalog create recovery compare created_by with the user the bundle already resolved, which deploy attaches to the context, so it no longer calls /Me. On the deploy path it works: PopulateCurrentUser always sets workspace.current_user before deployCore, and destroy never creates resources. What's left is small: a defensive nil check in deployCore, a test that doesn't pin the path it claims to cover, and a doc comment that still describes the old lookup.

Comments outside the changed lines

  • [nice to have] bundle/direct/dresources/schema_test.go:218: requireStatus(t, err, 504) also passes when the error is the recoveryError "exists but was created by another user", which wraps the same 504. Say the me == "" check were dropped and createdByCurrentUser compared "" with created_by: this test would still pass. Can you assert that errors.AsType[*recoveryError](err) fails, or compare err with the exact create error?

Comment thread bundle/phases/deploy.go
func deployCore(ctx context.Context, b *bundle.Bundle, plan *deployplan.Plan) {
// Apply resources and capture post-apply state. Finalize flushes the WAL to disk and
// returns the state; called even if Apply failed so partial progress is saved.
if u := b.Config.Workspace.CurrentUser; u != nil && u.User != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] b.Config.Workspace.CurrentUser and its User are always set by the time deployCore runs, because PopulateCurrentUser either sets both or fails the bundle earlier. AGENTS.md asks not to add nil checks for values the framework always provides, so can this just be ctx = dresources.WithCurrentUser(ctx, b.Config.Workspace.CurrentUser.UserName)? The new lines also sit between the "Apply resources and capture post-apply state…" comment and the Apply call it describes, so please move that comment down to Apply.

me, err := client.CurrentUser.Me(ctx, iam.MeRequest{Attributes: "", ExcludedAttributes: "", ForceSendFields: nil})
if err != nil {
return false, err
func createdByCurrentUser(ctx context.Context, createdBy string) (bool, error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit] The doc comment still only describes created_by. It doesn't say what it is compared with, or what happens when that is missing. Maybe: "Compares created_by with the user name attached by [WithCurrentUser]; without it, returns an error, so recoverCreate returns the create error instead of taking the resource over."

@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: dc64414

Run: 46023068537

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 173 17 3:49
💚​ aws-windows-latest-4core-16gb 1 173 17 3:23
💚​ azure linux-2core-8gb 1 172 17 3:27
💚​ azure-windows-latest-4core-16gb 1 172 17 3:18
💚​ gcp linux-2core-8gb 1 173 17 4:00
💚​ gcp-windows-latest-4core-16gb 1 173 17 2:39
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 6 slowest tests (at least 2 minutes):
duration env testname
4:00 gcp linux-2core-8gb TestAccept
3:26 aws linux-2core-8gb TestAccept
3:25 azure linux-2core-8gb TestAccept
3:22 aws-windows-latest-4core-16gb TestAccept
3:16 azure-windows-latest-4core-16gb TestAccept
2:38 gcp-windows-latest-4core-16gb TestAccept

This branch has not been deployed

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

Labels

DABs DABs related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants