ckan / ckanext-qa

CKAN QA Extension
MIT License
26 stars 52 forks source link

bad url join in celery task when site_url has a path components #20

Open dlax opened 8 years ago

dlax commented 8 years ago

Consider ckan.site_url = http://somehost/ckan in CKAN configuration file. With this, when building api_url here, one gets the wrong URL http://somehost/api/action because the "ckan" path component gets dropped by urljoin. One solution would be to have a trailing / in site_url configuration option but this is apparently not recommended. So I guess some url manipulation would be needed on extension side.

Note that other extensions (such as archiver and datastorer) have the same problem.

davidread commented 8 years ago

You're quite right.

How about changing it to:

api_url = urlparse.urljoin(context['site_url'] + '/', 'api/action')

Perhaps you could create some pull requests with this or similar change?

dlax commented 8 years ago

Yes I could. However, I'm not sure what the proper way to fix this. Sure your suggestion would work, but since this appears to be broken in other extensions as well, I was looking for a standard way to handle this... And looking into ckan source code, I could find a few different "solutions":

Did I miss something or should we really go and fix all usages of urljoin the way you suggests?

wardi commented 8 years ago

site_url shouldn't have path components, that's what root_path is for. The url_for helper can be used to generate full paths correctly, I think.