-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
AssertionError triggered for bug in Github #195
Comments
[What follows is obviously more general than I took this decision based on the following:
The consequence is "if Of course I could raise a more significant exception... raising an AssertionError is just laziness, but it wouldn't change anything for you; Can you please develop the "Be liberal in what you accept" part? What behavior would you propose for PyGithub in that case? I really don't want Thank you for your ideas, |
So, "Be liberal in what you accept" is a general protocol design principle, most famous from the IETF. (The full quote is, "Be conservative in what you send and liberal in what you accept.") The idea is that, when you set up a protocol data unit that you'll be sending, you want to be very strict in how you formulate it, to improve the chance that everyone will be able to understand it. On the other hand, when you're receiving a PDU, you want to be sensitive to the possibility that other people may have implemented ambiguous parts of the protocol differently from the way you're expecting, so you want to try hard to decode the PDU, even if it's not strictly what you're expecting. In this specific case, there is a single hook in the list returned by the local github instance that has a badly formatted "events" field. There are a range of options I could suggest for handling that; the first that occurs to me is to simply drop the single bad element. A second is to incorporate a workaround: if the list has one element which is also a list, unwrap the inner list. A third would be to use some sort of sentinel return value (None isn't the only option; you could make up your own, such as github.BadValue) to indicate that we couldn't parse the field; you could either return that or raise an exception if an attempt is made to access the element. As an example of the third possibility, you could do something like the following:
Then, if a value is an instance of BadValue, you raise it when an access attempt is made; the caller can catch it and look at the raw data, if they are so inclined. |
Not bad :) I will raise the exception when the user accesses the faulty attribute instead of when I create the object containing it. I will be happy because PyGithub will still not be silent about bad data returned by the API, and you will be happy because you will be able to use all the correct data. Wait for it in next version, I a week or two. Thanks, |
Done in @klmitch You may want to check github.test.BadAttributes.testIssue195 to see if this behavior is ok for you. I hope so, but if not, do not hesitate to reopen this issue. |
It's bad form to use assert to check the results from Github; the general advice is, "Be liberal in what you accept," and the violation of this principle has tripped me up. A minor bug in our local Github instance resulted in an assertion error popping up. This is a general complaint, but the specific case has to do with the Github.get_hooks() call; in our local Github instance, the "events" key of the "circleci" hook ends up being:
This makes it impossible to use get_hooks() to get the list of defined hooks.
The text was updated successfully, but these errors were encountered: