Repository navigation
Conversation
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>
There was a problem hiding this comment.
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 therecoveryError"exists but was created by another user", which wraps the same 504. Say theme == ""check were dropped andcreatedByCurrentUsercompared""withcreated_by: this test would still pass. Can you assert thaterrors.AsType[*recoveryError](err)fails, or compareerrwith the exact create error?
| 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 { |
There was a problem hiding this comment.
[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) { |
There was a problem hiding this comment.
[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."
✅ Integration test reportCommit: dc64414
Top 6 slowest tests (at least 2 minutes):
|
Changes
Unity Catalog create recovery (catalogs, schemas, volumes, external locations, registered models, secrets) now compares
created_bywithworkspace.current_user, which the bundle already resolved, instead of callingCurrentUser.Meon 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
/Merequest; newTestSchemaCreateRecoveryRequiresCurrentUser.TestCreateRecoveryCoveragesets the context user; without it the UC resources fail.This pull request and its description were written by Isaac.