Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

fix(dal,sdf): when finding change sets, ensure it belongs to the relevant workspace#5245

Merged
jkeiser merged 1 commit intomainfrom
brit/ensure-change-sets-belong-to-workspaces
Jan 15, 2025
Merged

fix(dal,sdf): when finding change sets, ensure it belongs to the relevant workspace#5245
jkeiser merged 1 commit intomainfrom
brit/ensure-change-sets-belong-to-workspaces

Conversation

@britmyerss
Copy link
Copy Markdown
Contributor

@britmyerss britmyerss commented Jan 13, 2025

This change introduces ChangeSet::find_across_workspaces to differentiate from ChangeSet::find to ensure we're not acting on ChangeSets that don't belong to the Workspace in question.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 13, 2025

Dependency Review

✅ No vulnerabilities or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

@britmyerss britmyerss requested a review from fnichol January 13, 2025 20:21
@github-actions github-actions bot added A-sdf Area: Primary backend API service [Rust] A-dal labels Jan 13, 2025

for change_set in open_change_sets {
let mut change_set = ChangeSet::find(ctx, change_set.id)
let mut change_set = ChangeSet::find_across_workspaces(ctx, change_set.id)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe this is correct - @zacharyhamm could use a check

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's hard to imagine this isn't correct, given the fact that these change set IDs came from list_open_for_all_workspaces()!. (Again, it at least doesn't make things worse.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is what we want, yes. The migrator will set up the dal context for the right visibility and tenancy but only after it finds the workspace, so this is definitely necessary

@britmyerss britmyerss force-pushed the brit/ensure-change-sets-belong-to-workspaces branch 2 times, most recently from 425cd9c to a5c49bb Compare January 13, 2025 22:36
@britmyerss
Copy link
Copy Markdown
Contributor Author

/try

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 13, 2025

Okay, starting a try! I'll update this comment once it's running...\n
🚀 Try running here! 🚀

@britmyerss britmyerss force-pushed the brit/ensure-change-sets-belong-to-workspaces branch 2 times, most recently from bded452 to f7f8e33 Compare January 14, 2025 00:28
/// for the current [`DalContext`]
pub async fn update_snapshot_to_visibility(&mut self) -> TransactionsResult<()> {
let change_set = ChangeSet::find(self, self.change_set_id())
let change_set = ChangeSet::find_across_workspaces(self, self.change_set_id())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could do a similar move here to have a tenancy-scoped version of this method, but not in this PR. Note that scoping this to the workspace breaks all of our integration tests at the moment.

.expect("could not build dal context");

//first, let's ensure we can't find it when using the user 1 dal ctx
let user_2_change_set_unfound = ChangeSet::find(&user_1_dal_context, user_2_change_set.id)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

before this change, we would User-1-Workspace-1 would successfully find (and be able to abandon) the change set in User-2's Workspace.

@britmyerss britmyerss marked this pull request as ready for review January 14, 2025 00:32
jkeiser
jkeiser previously approved these changes Jan 14, 2025
Copy link
Copy Markdown
Contributor

@jkeiser jkeiser left a comment

Choose a reason for hiding this comment

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

Super glad to see it narrowed down to just a few callers!

pub async fn apply_to_base_change_set(ctx: &mut DalContext) -> ChangeSetApplyResult<ChangeSet> {
// Apply to the base change with the current change set (non-editing) and commit.
let mut change_set_to_be_applied = Self::find(ctx, ctx.change_set_id())
let mut change_set_to_be_applied = Self::find_across_workspaces(ctx, ctx.change_set_id())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one might be able to be ChangeSet::find() (it seems like if we really need find_across_workspaces than we have been given a busted DalContext). But if you're worried about it or noticed it breaks things, I'm 100% on board with "fix most stuff and then look at these in another PR").

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah I think you're right! Will fix


for change_set in open_change_sets {
let mut change_set = ChangeSet::find(ctx, change_set.id)
let mut change_set = ChangeSet::find_across_workspaces(ctx, change_set.id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's hard to imagine this isn't correct, given the fact that these change set IDs came from list_open_for_all_workspaces()!. (Again, it at least doesn't make things worse.)

@britmyerss britmyerss force-pushed the brit/ensure-change-sets-belong-to-workspaces branch from f7f8e33 to 2603a0a Compare January 14, 2025 15:24
@britmyerss
Copy link
Copy Markdown
Contributor Author

/try

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 14, 2025

Okay, starting a try! I'll update this comment once it's running...\n
🚀 Try running here! 🚀

}
Ok(Some(change_set))
}
None => Ok(None),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we emitted an info or error here, we could track any time this returns None. Which should be almost never, except maybe stale URLs in cache for applied/abandoned change sets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(or set an attribute, whichever makes the most sense for a honeycomb query)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good shout - will add!

jkeiser
jkeiser previously approved these changes Jan 14, 2025
@britmyerss britmyerss force-pushed the brit/ensure-change-sets-belong-to-workspaces branch from 2603a0a to 8e15c47 Compare January 14, 2025 19:27
@britmyerss britmyerss requested a review from jkeiser January 15, 2025 02:20
Copy link
Copy Markdown
Contributor

@jkeiser jkeiser left a comment

Choose a reason for hiding this comment

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

Lock it down!

@jkeiser jkeiser added this pull request to the merge queue Jan 15, 2025
@jkeiser jkeiser removed this pull request from the merge queue due to a manual request Jan 15, 2025
@jkeiser jkeiser added this pull request to the merge queue Jan 15, 2025
Merged via the queue into main with commit 8ada592 Jan 15, 2025
@jkeiser jkeiser deleted the brit/ensure-change-sets-belong-to-workspaces branch January 15, 2025 21:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A-dal A-sdf Area: Primary backend API service [Rust]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants