-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(API): Updating assets via the API should preserve ownership configuration #27364
Changes from 3 commits
5519f19
187aea0
85d5ef9
2916487
22c38ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
from superset.connectors.sqla.models import BaseDatasource | ||
|
||
|
||
def populate_owners( | ||
def populate_owner_list( | ||
owner_ids: list[int] | None, | ||
default_to_user: bool, | ||
) -> list[User]: | ||
|
@@ -62,6 +62,25 @@ def populate_owners( | |
return owners | ||
|
||
|
||
def update_owner_list( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this is a pure function, but the name implies it's updating something but it's not, since it returns a newly created There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that makes sense! Updated the functions to |
||
current_owners: list[User] | None, | ||
new_owners: list[int] | None, | ||
) -> list[User]: | ||
""" | ||
Helper function for update commands, to properly handle the owners list. | ||
Preserve the previous configuration unless included in the update payload. | ||
|
||
:param current_owners: list of current owners | ||
:param new_owners: list of new owners specified in the update payload | ||
:returns: Final list of owners | ||
""" | ||
current_owners = current_owners or [] | ||
owners_ids = ( | ||
[owner.id for owner in current_owners] if new_owners is None else new_owners | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add this small unit test that will basically verify the that Something like this will do:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! I'm going to create a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hughhhh just added the unit tests 🙌 let me know if you have any feedback |
||
) | ||
return populate_owner_list(owners_ids, default_to_user=False) | ||
|
||
|
||
def populate_roles(role_ids: list[int] | None = None) -> list[Role]: | ||
""" | ||
Helper function for commands, will fetch all roles from roles id's | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was kind of confused thinking that the function was invoking itself to later realize that it's actually calling an utility function with the same name. Would you mind doing something like:
or renaming the utility functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that same reaction when started looking into this haha I kept it this flow because this was how
populate_owners
was implemented. I'll implement your first suggestion in a future commitThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ended up renaming the functions to avoid importing
utils
entirely.