You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
per create_instructor_answer's current documentation the post parameter can be either a string (the post's cid) or dictionary (post object with id key).
doesn't handle the type cases correctly. trying to index ["id"] in a string raises a TypeError not a KeyError so it doesn't get caught, and the fallback doesn't work. one possible fix is to catch the TypeError, as is done in some other functions, e.g. update_post:
:param post: Either the post dict returned by another API method, or
the `cid` field of that post.
:type subject: str
:param content: The content of the followup.
:rtype: dict
:returns: Dictionary with information about the updated post.
"""
try:
cid=post["id"]
exceptKeyError:
cid=post
exceptTypeError:
cid=post
another fix is to just simplify the API and only take in string post ID instead of str|dict|int; after all that is the only part of the post object needed, so it doesn't logically make sense to require the whole object. for most people typing out an additional ["id"] is not all that much added work, and the benefit is that the API is a lot more consistent and well-typed this way.
The text was updated successfully, but these errors were encountered:
per
create_instructor_answer
's current documentation thepost
parameter can be either a string (the post's cid) or dictionary (post object withid
key).piazza-api/piazza_api/network.py
Lines 192 to 211 in acb5de9
however passing in a string
post
actually causes an error/crash: that's becausepiazza-api/piazza_api/network.py
Lines 212 to 215 in acb5de9
doesn't handle the type cases correctly. trying to index
["id"]
in a string raises aTypeError
not aKeyError
so it doesn't get caught, and the fallback doesn't work. one possible fix is to catch theTypeError
, as is done in some other functions, e.g.update_post
:piazza-api/piazza_api/network.py
Lines 259 to 275 in acb5de9
another fix is to just simplify the API and only take in string post ID instead of
str|dict|int
; after all that is the only part of the post object needed, so it doesn't logically make sense to require the whole object. for most people typing out an additional["id"]
is not all that much added work, and the benefit is that the API is a lot more consistent and well-typed this way.The text was updated successfully, but these errors were encountered: