diff --git a/github/GithubException.py b/github/GithubException.py index 0186c690..c72fad89 100644 --- a/github/GithubException.py +++ b/github/GithubException.py @@ -123,3 +123,9 @@ class TwoFactorException(GithubException): """ Exception raised when Github requires a onetime password for two-factor authentication """ + + +class IncompletableObject(GithubException): + """ + Exception raised when we can not request an object from Github because the data returned did not include a URL + """ diff --git a/github/GithubObject.py b/github/GithubObject.py index f6a817aa..41581a56 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -266,6 +266,8 @@ class CompletableGithubObject(GithubObject): self.__complete() def __complete(self): + if self._url.value is None: + raise GithubException.IncompletableObject(400, "Returned object contains no URL") headers, data = self._requester.requestJsonAndCheck( "GET", self._url.value diff --git a/tests/Exceptions.py b/tests/Exceptions.py index 0f137765..9ee5dae4 100644 --- a/tests/Exceptions.py +++ b/tests/Exceptions.py @@ -33,6 +33,7 @@ from __future__ import absolute_import import github +from github.GithubException import IncompletableObject import pickle from . import Framework @@ -122,3 +123,8 @@ class SpecificExceptions(Framework.TestCase): res.get_page(0) self.assertRaises(github.RateLimitExceededException, exceed) + + def testIncompletableObject(self): + github.UserKey.UserKey.setCheckAfterInitFlag(False) + obj = github.UserKey.UserKey(None, {}, {}, False) + self.assertRaises(IncompletableObject, obj._completeIfNeeded)