Repository: PyGithub/PyGithub

Issue:
get_repo() doesn't raise 404
I have code that is expecting get_repo() to raise an UnknownObjectException if it calls get_repo() on a repository that doesn't exist.  With the 1.26.0 release, this is no longer happening; get_repo() returns an object, then subsequent (unprotected) code is getting the UnknownObjectException when it attempts to refer to an attribute on that object (in this case, full_name).



Discussion:
Is there any movement on this?  This is a very serious bug that prevents me from using the latest version of PyGithub…

I'm getting 404 on get_repo("repo_not_present") as intended.

```
github_instance = Github("acsrujan", "password")
user = github_instance.get_user()
user.get_repo("repo_not_present")
---------------------------------------------------------------------------
UnknownObjectException                    Traceback (most recent call last)
<ipython-input-22-50a1bf2f4078> in <module>()
----> 1 user.get_repo("repo_not_present")
/Users/acsrujan/projects/github-in-github/test-gig/lib/python2.7/site-packages/github/AuthenticatedUser.pyc in get_repo(self, name)
    843         headers, data = self._requester.requestJsonAndCheck(
    844             "GET",
--> 845             "/repos/" + self.login + "/" + name
    846         )
    847         return github.Repository.Repository(self._requester, headers, data, completed=True)

/Users/acsrujan/projects/github-in-github/test-gig/lib/python2.7/site-packages/github/Requester.pyc in requestJsonAndCheck(self, verb, url, parameters, headers, input, cnx)
    169
    170     def requestJsonAndCheck(self, verb, url, parameters=None, headers=None, input=None, cnx=None):
--> 171         return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
    172
    173     def requestMultipartAndCheck(self, verb, url, parameters=None, headers=None, input=None):

/Users/acsrujan/projects/github-in-github/test-gig/lib/python2.7/site-packages/github/Requester.pyc in __check(self, status, responseHeaders, output)
    177         output = self.__structuredFromJson(output)
    178         if status >= 400:
--> 179             raise self.__createException(status, responseHeaders, output)
    180         return responseHeaders, output
    181

UnknownObjectException: 404 {u'documentation_url': u'https://developer.github.com/v3', u'message': u'Not Found'}
```

Can you try that using the top-level get_repo() method call with the repository's full name?  I'm not using the user-level get_repo() call.

Thank you both for reporting and looking into this issue. @klmitch I have determined that the top level `get_repo` method does not raise, while the user-level `get_repo` does.


Resolving patch:
diff --git a/github/MainClass.py b/github/MainClass.py
--- a/github/MainClass.py
+++ b/github/MainClass.py
@@ -273,7 +273,7 @@ def get_organizations(self, since=github.GithubObject.NotSet):
             url_parameters
         )
 
-    def get_repo(self, full_name_or_id, lazy=True):
+    def get_repo(self, full_name_or_id, lazy=False):
         """
         :calls: `GET /repos/:owner/:repo <http://developer.github.com/v3/repos>`_ or `GET /repositories/:id <http://developer.github.com/v3/repos>`_
         :rtype: :class:`github.Repository.Repository`


Test patch:
diff --git a/github/tests/BadAttributes.py b/github/tests/BadAttributes.py
--- a/github/tests/BadAttributes.py
+++ b/github/tests/BadAttributes.py
@@ -85,7 +85,7 @@ def testBadAttributeInClassAttribute(self):
         self.assertEqual(raisedexp.exception.actual_value, 42)
 
     def testBadTransformedAttributeInList(self):
-        commit = self.g.get_repo("klmitch/turnstile").get_commit("38d9082a898d0822b5ccdfd78f3a536e2efa6c26")
+        commit = self.g.get_repo("klmitch/turnstile", lazy=True).get_commit("38d9082a898d0822b5ccdfd78f3a536e2efa6c26")
 
         with self.assertRaises(github.BadAttributeException) as raisedexp:
             commit.files
diff --git a/github/tests/Branch.py b/github/tests/Branch.py
--- a/github/tests/Branch.py
+++ b/github/tests/Branch.py
@@ -41,7 +41,7 @@ def setUp(self):
         self.repo = self.g.get_user().get_repo("PyGithub")
         self.branch = self.repo.get_branch("topic/RewriteWithGeneratedCode")
         self.protected_branch = self.repo.get_branch("integrations")
-        self.organization_branch = self.g.get_repo("PyGithub/PyGithub").get_branch("master")
+        self.organization_branch = self.g.get_repo("PyGithub/PyGithub", lazy=True).get_branch("master")
 
     def testAttributes(self):
         self.assertEqual(self.branch.name, "topic/RewriteWithGeneratedCode")
diff --git a/github/tests/CommitCombinedStatus.py b/github/tests/CommitCombinedStatus.py
--- a/github/tests/CommitCombinedStatus.py
+++ b/github/tests/CommitCombinedStatus.py
@@ -34,7 +34,7 @@
 class CommitCombinedStatus(Framework.TestCase):
     def setUp(self):
         Framework.TestCase.setUp(self)
-        self.combined_status = self.g.get_repo("edx/edx-platform").get_commit("74e70119a23fa3ffb3db19d4590eccfebd72b659").get_combined_status()
+        self.combined_status = self.g.get_repo("edx/edx-platform", lazy=True).get_commit("74e70119a23fa3ffb3db19d4590eccfebd72b659").get_combined_status()
 
     def testAttributes(self):
         self.assertEqual(self.combined_status.state, "success")
diff --git a/github/tests/Issue494.py b/github/tests/Issue494.py
--- a/github/tests/Issue494.py
+++ b/github/tests/Issue494.py
@@ -29,7 +29,7 @@
 class Issue494(Framework.TestCase):
     def setUp(self):
         Framework.TestCase.setUp(self)
-        self.repo = self.g.get_repo("apache/brooklyn-server")
+        self.repo = self.g.get_repo("apache/brooklyn-server", lazy=True)
         self.pull = self.repo.get_pull(465)
 
     def testRepr(self):
diff --git a/github/tests/IssueEvent.py b/github/tests/IssueEvent.py
--- a/github/tests/IssueEvent.py
+++ b/github/tests/IssueEvent.py
@@ -36,41 +36,42 @@
 class IssueEvent(Framework.TestCase):
     def setUp(self):
         Framework.TestCase.setUp(self)
+        repo = self.g.get_repo("PyGithub/PyGithub", lazy=True)
 
         # From Issue #30
-        self.event_subscribed               = self.g.get_repo("PyGithub/PyGithub").get_issues_event(16347479)
-        self.event_assigned                 = self.g.get_repo("PyGithub/PyGithub").get_issues_event(16347480)
-        self.event_referenced               = self.g.get_repo("PyGithub/PyGithub").get_issues_event(16348656)
-        self.event_closed                   = self.g.get_repo("PyGithub/PyGithub").get_issues_event(16351220)
-        self.event_labeled                  = self.g.get_repo("PyGithub/PyGithub").get_issues_event(98136337)
+        self.event_subscribed = repo.get_issues_event(16347479)
+        self.event_assigned = repo.get_issues_event(16347480)
+        self.event_referenced = repo.get_issues_event(16348656)
+        self.event_closed = repo.get_issues_event(16351220)
+        self.event_labeled = repo.get_issues_event(98136337)
 
         # From Issue 538
-        self.event_mentioned                = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1009034767)
-        self.event_merged                   = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1015402964)
-        self.event_review_requested         = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1011101309)
+        self.event_mentioned = repo.get_issues_event(1009034767)
+        self.event_merged = repo.get_issues_event(1015402964)
+        self.event_review_requested = repo.get_issues_event(1011101309)
 
         # From Issue 857
-        self.event_reopened                 = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1782463023)
-        self.event_unassigned               = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1782463379)
-        self.event_unlabeled                = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1782463917)
-        self.event_renamed                  = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1782472556)
-        self.event_base_ref_changed         = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1782915693)
-        self.event_head_ref_deleted         = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1782917185)
-        self.event_head_ref_restored        = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1782917299)
-        self.event_milestoned               = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1783596418)
-        self.event_demilestoned             = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1783596452)
-        self.event_locked                   = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1783596743)
-        self.event_unlocked                 = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1783596818)
-        self.event_review_dismissed         = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1783605084)
-        self.event_review_request_removed   = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1783779835)
-        self.event_marked_as_duplicate      = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1783779725)
-        self.event_unmarked_as_duplicate    = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1789228962)
-        self.event_added_to_project         = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1791766828)
-        self.event_moved_columns_in_project = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1791767766)
-        self.event_removed_from_project     = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1791768212)
+        self.event_reopened = repo.get_issues_event(1782463023)
+        self.event_unassigned = repo.get_issues_event(1782463379)
+        self.event_unlabeled = repo.get_issues_event(1782463917)
+        self.event_renamed = repo.get_issues_event(1782472556)
+        self.event_base_ref_changed = repo.get_issues_event(1782915693)
+        self.event_head_ref_deleted = repo.get_issues_event(1782917185)
+        self.event_head_ref_restored = repo.get_issues_event(1782917299)
+        self.event_milestoned = repo.get_issues_event(1783596418)
+        self.event_demilestoned = repo.get_issues_event(1783596452)
+        self.event_locked = repo.get_issues_event(1783596743)
+        self.event_unlocked = repo.get_issues_event(1783596818)
+        self.event_review_dismissed = repo.get_issues_event(1783605084)
+        self.event_review_request_removed = repo.get_issues_event(1783779835)
+        self.event_marked_as_duplicate = repo.get_issues_event(1783779725)
+        self.event_unmarked_as_duplicate = repo.get_issues_event(1789228962)
+        self.event_added_to_project = repo.get_issues_event(1791766828)
+        self.event_moved_columns_in_project = repo.get_issues_event(1791767766)
+        self.event_removed_from_project = repo.get_issues_event(1791768212)
         
         # From Issue 866
-        self.event_converted_note_to_issue  = self.g.get_repo("PyGithub/PyGithub").get_issues_event(1791769149)
+        self.event_converted_note_to_issue = repo.get_issues_event(1791769149)
 
     def testEvent_subscribed_Attributes(self):
         self.assertEqual(self.event_subscribed.actor.login, "jacquev6")
diff --git a/github/tests/PullRequest.py b/github/tests/PullRequest.py
--- a/github/tests/PullRequest.py
+++ b/github/tests/PullRequest.py
@@ -42,10 +42,11 @@ def setUp(self):
         self.repo = self.g.get_user().get_repo("PyGithub")
         self.pull = self.repo.get_pull(31)
 
-        self.pullIssue256Closed = self.g.get_repo("MarcoFalke/PyGithub").get_pull(1)
-        self.pullIssue256Merged = self.g.get_repo("MarcoFalke/PyGithub").get_pull(2)
-        self.pullIssue256Conflict = self.g.get_repo("MarcoFalke/PyGithub").get_pull(3)
-        self.pullIssue256Uncached = self.g.get_repo("MarcoFalke/PyGithub").get_pull(4)
+        marco_repo = self.g.get_repo("MarcoFalke/PyGithub", lazy=True)
+        self.pullIssue256Closed = marco_repo.get_pull(1)
+        self.pullIssue256Merged = marco_repo.get_pull(2)
+        self.pullIssue256Conflict = marco_repo.get_pull(3)
+        self.pullIssue256Uncached = marco_repo.get_pull(4)
 
     def testAttributesIssue256(self):
         self.assertEqual(self.pullIssue256Closed.closed_at, datetime.datetime(2018, 5, 22, 14, 50, 43))
diff --git a/github/tests/PullRequestReview.py b/github/tests/PullRequestReview.py
--- a/github/tests/PullRequestReview.py
+++ b/github/tests/PullRequestReview.py
@@ -34,7 +34,7 @@
 class PullRequestReview(Framework.TestCase):
     def setUp(self):
         Framework.TestCase.setUp(self)
-        self.repo = self.g.get_repo("PyGithub/PyGithub")
+        self.repo = self.g.get_repo("PyGithub/PyGithub", lazy=True)
         self.pull = self.repo.get_pull(538)
 
         # Test ability to create a review
diff --git a/github/tests/RequiredPullRequestReviews.py b/github/tests/RequiredPullRequestReviews.py
--- a/github/tests/RequiredPullRequestReviews.py
+++ b/github/tests/RequiredPullRequestReviews.py
@@ -41,6 +41,6 @@ def testAttributes(self):
         self.assertEqual(self.required_pull_request_reviews.__repr__(), 'RequiredPullRequestReviews(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_pull_request_reviews", require_code_owner_reviews=True, dismiss_stale_reviews=True)')
 
     def testOrganizationOwnedTeam(self):
-        required_pull_request_reviews = self.g.get_repo("PyGithub/PyGithub").get_branch("integrations").get_required_pull_request_reviews()
+        required_pull_request_reviews = self.g.get_repo("PyGithub/PyGithub", lazy=True).get_branch("integrations").get_required_pull_request_reviews()
         self.assertListKeyEqual(required_pull_request_reviews.dismissal_users, lambda u: u.login, ["jacquev6"])
         self.assertListKeyEqual(required_pull_request_reviews.dismissal_teams, lambda t: t.slug, ["pygithub-owners"])