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

Fetch remote organization via action api #121

Merged
merged 7 commits into from Jan 15, 2015

Conversation

metaodi
Copy link
Member

@metaodi metaodi commented Jan 13, 2015

Organizations used to be returned by /api/2/rest/group, this is what the
old implementation used to fetch the information to create the remote
organization on the local instance of CKAN.

With this commit the Action API is used to fetch the same information.

Fixes #120

Stefan Oderbolz added 2 commits January 13, 2015 14:46
Organizations used to be returned by /api/2/rest/group, this is what the
old implementation used to fetch the information to create the remote
organization on the local instance of CKAN.

With this commit the Action API is used to fetch the same information.
First try to get a remote org from the remote Action API, if this fails
try to use the old rest api call, which works on older CKAN versions.

Only if both options fail, its currently not possible to get the remote
organization.
org = self._get_group(harvest_object.source.url, remote_org)
try:
org = self._get_organization(harvest_object.source.url, remote_org)
except:
Copy link
Member

Choose a reason for hiding this comment

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

@metaodi this is bad, see comment above

@davidread
Copy link
Contributor

PS Cheers for submitting this - most helpful

Stefan Oderbolz added 3 commits January 15, 2015 00:44
1. Try whenever possible to catch specific exceptions
2. Raise custom exception where appropriate
3. Fix the exception handling in _get_group and _get_organization
The API call /api/2/rest/package/<id> returns the display name of the
group instead of its ID. To properly match the group, munge the name
before calling /api/2/rest/group
@metaodi
Copy link
Member Author

metaodi commented Jan 15, 2015

@davidread @amercader okay, I tried to clean this all up. I introduced two now *Error classes, one to wrap the urllib2 exception and one to wrap either the HTTP or the json parse error. I replaced all generic except: blocks and almost all generic Exception usages in the CKANHarvester.

During my tests I also found an issue with the remote_groups, if you want me to create a separate PR for that, just let me know.

raise ContentFetchError(
'Could not fetch url: %s, HTTP error code: %s' %
(url, e.code)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this also needs to catch urllib2.URLError, in cases such as where the url has bad syntax, or the socket connection times out.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I'll replace it with urllib2.URLError (which is the super class of urllib2.HTTPError), this should cover the exceptions at this point.

@davidread
Copy link
Contributor

Thanks @metaodi - I think that's another really valuable improvement

HTTPError is a subclass of URLError, so catch URLError is enough. I
think the HTTP error code is not as important in this situation, so
catching the more generic error seems like the best solution.
@davidread
Copy link
Contributor

I didn't know about HTTPError inheriting URLError - cheers!

@metaodi
Copy link
Member Author

metaodi commented Jan 15, 2015

@davidread a thanks for this hint, replaced it with str() as you suggested.

davidread pushed a commit that referenced this pull request Jan 15, 2015
Fetch remote organization via action api
@davidread davidread merged commit b3ed6ca into ckan:master Jan 15, 2015
@davidread
Copy link
Contributor

Thanks @metaodi

@metaodi metaodi deleted the 120-create-remote-orgs branch January 15, 2015 10:51
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.

Creating remote orgs does not work
3 participants