-
Notifications
You must be signed in to change notification settings - Fork 196
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
Updating a dashboard element query model using Python #1188
Comments
Hi @lambdamusic. I do have a workaround What could be done is
So something like this
Haven't tested the exact script above. But the flow should be the way as described above. |
Thanks @k7ragav for the tip! Seems to go in the right direction but can't get it to work still. The WriteQuery builder does not have a from looker_sdk import models
altered_query = myelement.query
altered_query['model'] = 'fake_model'
altered_query['id'] = None
altered_query['client_id'] = None # Needed by the create_query method below
new_query = sdk.create_query(body = altered_query)
# THIS BREAKS
sdk.update_dashboard_element(
dashboard_element_id = myelement.id,
body = models.WriteQuery(query_id = new_query.id))
>>>
>>> TypeError: __init__() got an unexpected keyword argument 'query_id'
>>> I tried to construct the That seems to be working in the sense that I get no errors and a 200 from Looker. But no visible results in the Looker dashboard itself! my_instance = models.WriteQuery(
model=new_query.model,
view=new_query.view,
fields=new_query.fields,
pivots=new_query.pivots,
fill_fields=new_query.fill_fields,
filters=None,
sorts=new_query.sorts,
limit=new_query.limit,
column_limit=new_query.column_limit,
total=new_query.total,
row_total=new_query.row_total,
subtotals=new_query.subtotals,
dynamic_fields=new_query.dynamic_fields,
query_timezone=new_query.query_timezone,
)
# WORKS, BUT NO EFFECTS IN LOOKER
sdk.update_dashboard_element(
dashboard_element_id = myelement.id,
body = my_instance) After the last operation, in Looker I'd expect to see the query failing cause "fake_model" does not exist... unless I'm missing something here! What do you think? |
Hi @lambdamusic Maybe could you try this in the first snippet.
Let's see if that works 🤞 |
That works :-) Posting again the full solution for posterity's sake: import looker_sdk
sdk = looker_sdk.init40()
from looker_sdk import models
myelement = sdk.dashboard_element("1196") # change as needed
altered_query = myelement.query
print("Old Model: ", altered_query['model'])
altered_query['model'] = 'fake-model'
print("New Model: ", altered_query['model'])
altered_query['id'] = None
altered_query['client_id'] = None
new_query = sdk.create_query(body = altered_query)
sdk.update_dashboard_element(
dashboard_element_id = myelement.id,
body = models.WriteDashboardElement(query_id = new_query.id)) Thanks again @k7ragav |
I have a dashboard and would like to update the LookML
model
used in all of its tiles / queries.Context: we are migrating the dashboard to different model implementation. So trying to automate an otherwise tedious manual task.
I got this far by using update_dashboard_element, but struggle to understand the model updating API:
Any help greatly appreciated!
The text was updated successfully, but these errors were encountered: