GitHub user jbat edited a comment on the discussion: how to update  DataSet 
Owner in Superset bulk update on database

@devikaaaa33  I would recommend you use the Superset API for this.

Doing direct database updates may skip some application logic that needs to be 
applied as part of the update process,
hence the comment above regarding a DB update will  _"bypasses Superset’s ORM 
hooks and permission sync logic"_

https://superset.apache.org/docs/api/#api

All primary objects in superset have a PUT endpoint for updating the assets 
attributes.
A simple loop over your set of dataset ids would do it.

PUT https://your-superset-url/api/v1/dashboard/15, {:owners=>[1,3,8]}

There is a ruby superset api client that makes this pretty seamless.
https://github.com/rdytech/superset-client

```ruby
additional_owner_id = 101

# get ids of all sales datasets
dataset_ids = Superset::Dataset::List.new(title_contains: 
'sales').rows.map(&:first)

# loop over them and add the additional_owner_id to each datasets current 
owners list
dataset_ids.each do |dataset_id|
  current_owner_ids = 
Superset::Dashboard::Get.new(dataset_id).result['owners'].map {|o| o['id'] }
  Superset::Dataset::Put.new(object_id: dataset_id, params: { owners: 
current_owner_ids << additional_owner_id } ).perform
end
```

GitHub link: 
https://github.com/apache/superset/discussions/34168#discussioncomment-13827121

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: 
notifications-unsubscr...@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to