-
Notifications
You must be signed in to change notification settings - Fork 175
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
Awkward to set context_codes[] parameter in Calendar.list_calendar_events call #55
Comments
Hey @liblit, thanks for reporting this issue! Yeah, this is definitely not intentional behavior. Good idea to use Despite the documentation listing the type as Do you think implementing it such that passing in a list as an argument auto-adds the brackets would be sufficient? |
You are most welcome, @Thetwam. Thank you for providing
Ah, good catch about Canvas's own API documentation giving the wrong type (or at least a confusing type) for this parameter. If I look for other examples of attributes ending in
Yes, that seems quite natural. Perhaps you could add brackets for tuples as well? I generally use tuples rather than lists when the number of items is fixed and known to me in advance. |
There is something strange about that submissions = connect.list_multiple_submissions(assignment_ids=123, ...) # OK
submissions = connect.list_multiple_submissions(assignment_ids=[123, 456], ...) # OK
submissions = connect.list_multiple_submissions(assignment_ids=(123, 456), ...) # OK All of the above work. For a single value, this turns into a request URL that includes Compare this with the Weird. Is this a Canvas bug? |
Yet further experimentation shows that So I think this brings us back to where we were earlier, with @Thetwam’s suggested fix:
Yes, I still think this is the right approach. Furthermore, it seems this should be done for all parameters, not merely |
What you've stumbled upon is a feature of the Requests library. Given a list, it automatically splits the parameters up. Some webservers accept So, my earlier suggestion of the library auto-appending ...until we run into stuff like creating grading standards with params like The way we currently handle kwargs is by flattening the dictionaries into entries that look like
We can probably get around number 1 by using |
@Thetwam, thank you for your patience as I haphazardly rediscover things you already know about If I understand the problem correctly, it arises in the However, tracing down into the
So this makes me think that the “Dictionary or bytes” mentioned in the [('grading_scheme_entry[][name]', 'pass'),
('grading_scheme_entry[][value]', 50),
('grading_scheme_entry[][name]', 'fail'),
('grading_scheme_entry[][value]', 0)] Regarding the higher-level API for creating grading scheme entries, perhaps we can leverage my relative ignorance. Let me ponder how I would expect to provide data for such a call. Reading just the Create a new grading standard Canvas REST API documentation, and knowing very little about how such things work, I would assume that one of the following styles would work:
In each of these cases, I am expecting to pass in a single value for the |
That list of tuples thing looks really interesting, gonna give that a shot right now. As far as what the developer can expect to pass, I'd imagine it looking something like: g_scheme = [
{
'name': 'pass',
'value': 50
},
{
'name': 'fail',
'value': 0
}
]
course.create_grading_scheme(title='Title', grading_scheme_entry=g_scheme)
Yeah, we've had trouble expressing exactly how we handle nested kwargs in the documentation (Hence this issue: #9). Figuring out how to handle these weird args will go a long way in making that documentation easier to write/generate! |
That matches option 2 from my list. I would find this perfectly usable and unsurprising: two qualities that a good API should exhibit. |
Good news! I did a quick test using the list of 2-tuples format and it worked! I'm still working on the best way to translate the format that I mentioned before into the list of 2-tuples format, but I can see the light at the end of the tunnel! |
@jessemcbride Issue is essentially complete, but not merged into master yet. Once we do a release, I'll close the issue. |
The
Canvas.list_calendar_events
method feeds its parameters down to aGET /api/v1/calendar_events
request. That request accepts acontext_codes[]
parameter, but setting that parameter correctly is surprisingly awkward in version 0.6.0 ofcanvasapi
. The problem is that the parameter name really must becontext_codes[]
, notcontext_codes
, but creating a Python keyword argument with brackets in its name is subtle:The syntactically invalid ones I knew were wrong before I even tried them. But for the first two attempts shown above, I guess I expected
canvasapi
to add the brackets for me either because it knew thatcontext_codes[]
was special, or perhaps it would always append brackets when I passed a value as a list ([context]
) rather than a single item.Arguably this is my fault: give the wrong parameter name, and of course things will fail. But I would have hoped that
canvasapi
would make this easier. The use of**{...}
is obscure enough that manycanvasapi
users may not know how to do it at all.The text was updated successfully, but these errors were encountered: