Skip to content
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

Chris/remove redirect from slice id endpoint #1044

Merged
merged 5 commits into from
Aug 31, 2016

Conversation

williaster
Copy link
Contributor

@williaster williaster commented Aug 30, 2016

@mistercrunch

I used the approach we discussed yesterday for avoiding a re-direct for the /caravel/slice/id endpoint. It required a bit of refactoring of the explore method but not too bad. Overall if a slice_id is passed as part of the URL pathname I'll use that, then fall back to the URL query, else None.

In the case that a slice_id is found I update the database slice params with any specified in the URL. I coerce the updated param dict to a ImmutableMultiDict so that its type is consistent with request.args. I ran into a reported MultiDict bug wherein if you initialize an ImmutableMultiDict with a dict containing a key whose value is an empty array, if you try to access that key, an IndexError is thrown. I added a try catch for this where I was seeing errors. eg:

md = MultiDict({ groupby: [] })
md.keys() # returns ['groupby']
md['groupby'] # IndexError
md.get('groupby') # IndexError

As noted I also found another bug where slices that have been over-written are saved with the original slice_id which caused weird bugs in the forms. I fixed this in the save_slice_as method and explicitly set the slice_id in the slice_params I use to the value passed in the URL.

Updated tests / they all passed.

if not (all_datasource_access or datasource_access):
flash(__("You don't seem to have access to this datasource"),
"danger")
return redirect(error_redirect)

action = request.args.get('action')
# handle slc / viz obj
slice_id = slice_id if slice_id != None else request.args.get("slice_id")
Copy link
Member

Choose a reason for hiding this comment

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

pythonesque coalesce:
silce_id = slice_id or request.args.get('slice_id')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does this work for slice_id = 0 because slice_id is actually a string? thinking too much in JS.

Copy link
Member

Choose a reason for hiding this comment

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

you can do int(request.args.get("slice_id"))

@williaster williaster force-pushed the chris/remove-redirect-from-slice-id-endpoint branch 2 times, most recently from e7e4a2f to 64b1f99 Compare August 31, 2016 00:51
@mistercrunch
Copy link
Member

mistercrunch commented Aug 31, 2016

Code looks good, but Travis says no :(

@williaster
Copy link
Contributor Author

yeah js linting error. didn't change any js so will look into what's up.

@williaster williaster force-pushed the chris/remove-redirect-from-slice-id-endpoint branch from 64b1f99 to 35acfd9 Compare August 31, 2016 16:45
@williaster williaster force-pushed the chris/remove-redirect-from-slice-id-endpoint branch from 35acfd9 to af2fc94 Compare August 31, 2016 21:55
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 26, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.11.0 labels Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants