Thanks to visit codestin.com
Credit goes to github.com

Skip to content

h.remove_url_param fail with minimal set of params#6414

Merged
wardi merged 3 commits into
masterfrom
remove_url_param-on-current-page
Sep 21, 2021
Merged

h.remove_url_param fail with minimal set of params#6414
wardi merged 3 commits into
masterfrom
remove_url_param-on-current-page

Conversation

@smotornyuk
Copy link
Copy Markdown
Member

h.remove_url_param with the minimal set of parameters:

h.remove_url_param("q")

will throw an error on the organization.read page(not only here). Because internally it gets current blueprint and view (g.controller and g.action) and tries to build the URL h.url_for(blueprint + "." + view). And as long as the given blueprint requires extra arguments (package_type for dataset pages, group_type/is_organization for group pages, id for organization.read page, etc), this will fail. User has to do something like

h.remove_url_param("q", extras={"is_organization": group_dict.type, id=group_dict.id, "group_type": group_dict.type})

While it is perfectly ok from the clarity point of view, it requires every developer to know CKAN internals and these extra parameters. And it makes the given helper too fragile. In addition, the extras parameter is optional, so there may be some expectations, like
whenever I'm using h.remove_url_param("q") in the simplest form, I expect q to be removed from the CURRENT URL, whatever it is

This PR takes all the extra parameters required to build the current URL and adds them only when neither controller nor action nor extras argument is present. I.e, only when the user trying to modify the current URL.

PS. And it also updates toolkit.get_endpoint. Now it won't raise RuntimeError in CLI. Instead, its returns None, None, which is quite safe, I think.

@smotornyuk smotornyuk force-pushed the remove_url_param-on-current-page branch from 6771206 to 5c0bd2d Compare September 17, 2021 08:32
@wardi wardi merged commit b472767 into master Sep 21, 2021
@wardi wardi deleted the remove_url_param-on-current-page branch September 21, 2021 13:41
@frafra
Copy link
Copy Markdown
Contributor

frafra commented Dec 15, 2021

Will this be backported to CKAN 2.9?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filters on dataset types different from "datasets" are not selective

3 participants