-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Import / export of the dashboards. #1197
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
Conversation
|
what is the use case for importing/exporting slices and dashboards? |
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.
could we do this redirect in the views.py rather than in an html template?
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.
the challenge here is to download a file and redirect right after, flask doesn't provide an easy way to do that :(
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.
since action="" you can leave it out altogether and it will still post to the current url.
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.
missing closing </p> tag
caravel/models.py
Outdated
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.
is this a typo? find('(id') or find('id')
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.
added a comment describing how the perm string is created.
caravel/views.py
Outdated
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 think fa-flask is for SQL Lab, here should be some file-import icon?
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.
Thanks, changed the icon.
Here is the list: http://fontawesome.io/icons/
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.
maybe this one:
http://fontawesome.io/icon/files-o/
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.
oops, missed your comment @bkyryliuk 👍
caravel/models.py
Outdated
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.
let's add a perm_slice_id property to Slice, I think some other place in the code used a regex to do something like this, let's always use that new property instead.
That property should raise if the perm is malformed.
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.
refactored in a way that there is no need to use the permission anymore
caravel/models.py
Outdated
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.
filter_by missing?,
we may want a shortcut function SourceRegistry.get_datasource(type, id, session=None)
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.
filter by doesn't work for lookups by name, created function SourceRegistry.get_datasource_by_name
caravel/models.py
Outdated
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.
If we assume that the datasource should always exist we sould just raise.
caravel/models.py
Outdated
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.
a new method Slice.alert_params(**kwargs) could be useful here, resulting in a simple call:
slc.alert_params(remote_id=slc.id, import_time=import_time)
caravel/models.py
Outdated
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.
seems brittle, you should at least have a comma after the {} otherwise slice_id=5 would match with 5.*
tests/core_tests.py
Outdated
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.
create_slice
tests/core_tests.py
Outdated
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.
create_dashboard
tests/core_tests.py
Outdated
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.
get_dash
tests/core_tests.py
Outdated
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.
.one()
tests/core_tests.py
Outdated
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.
assert imported_dash_4.dashboard_title == imported_dash_2.dashboard_title instead of hard coding the title twice
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.
imported_dash_2 doesn't exist when this check is done, sqlalchemy magic.
|
@mistercrunch - please take another look. PR is getting bigger :( |
caravel/models.py
Outdated
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.
d = self.params_dict
d.update(kwargs)
self.params = json.dumps(d)
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.
@mistercrunch - done
caravel/models.py
Outdated
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.
NIT (optional): by convention s is used for short lived strings
caravel/models.py
Outdated
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.
params = slc.params_dict
caravel/source_registry.py
Outdated
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.
Why returning everything and filtering on the server? You should just use a filter in session.query and use .one()
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 wish that was that easy. I need to use properties for filtering, otherwise I have to implement 2 separate queries, as druid and table reference databases using different attributes. @mistercrunch
caravel/views.py
Outdated
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.
dup with line 35
caravel/views.py
Outdated
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.
Dashboard List
tests/import_export_tests.py
Outdated
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.
the outer comprehension doesn't do anything
tests/import_export_tests.py
Outdated
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.
NIT: I personally prefer having a smaller atomicity of tests and no number-suffixed variables. Shared items can be refactored into the class or module scope, methods won't run if it doesn't start with test_.
If case 5 fails here there's just more stuff to look at, understand whether case 5 is tangled with other tests or not.
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.
yeah, in this case test cases are build upon each other. I'll try to separate them.
tests/import_export_tests.py
Outdated
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.
requires_examples should be set to True here as you assume examples have been loaded
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.
leftovers, sorry
tests/import_export_tests.py
Outdated
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.
Would if make sense to cleanup at the beginning to setup to test? if the test fails half way, it's nice to be able to assume that you can just re-run the test itself (not the full suite) to fix the state. Idempotent, atomic tests ftw!
caravel/models.py
Outdated
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.
There's a lot in common in all these import_obj methods. It'd be nice to distill some of it into re-usable chunks, maybe adding a CaravelModel base class and adding a get_or_create @classmethod. The second answer here is inspiring:
http://stackoverflow.com/questions/2546207/does-sqlalchemy-have-an-equivalent-of-djangos-get-or-create
And maybe a generic import_obj if that's reasonable though that might be tricky with relationships, so not a requirement for this PR...
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.
@mistercrunch - making query to retrieve the object that have remote id is not possible as "remote_id": {id} could be in the end of the json and there will be no comma after it. Json doesn't support trailing commas. Because of it I loop through all slices / dashboards to find the object to override.
I see 2 possible solutions:
- use
"remote_id": {id}{prefix}instead - add remote_id field to the model
What would you suggest?
Would it be fine to have it in the separate PR ?
|
LGTM! |
|
thanks @mistercrunch ! |

Provides import export functionality for the dashboards using pickle library to serialize the objects. It requires the tables to have the same names to be able to hook slices up to them.
Import overrides the existing dashboards and slices. Newly added metrics and table column will stay, old definition will be overridden.
Git Issues: #1237. #1173
Exports:
Code:
remote_id,database_nameto be able to locate and recreated the dependenciesFuture works:
Tested:
Reviewers:
CC: