fix: Course blocks API with param return_type=list
Discussion: edx (New). Issue Link Endpoint: {LMS_HOST}/api/courses/v1/blocks/?course_id={COURSE_ID}&return_type=list
Root cause
When return_type is set to list in querystring the api endpoint is crashing because it is calling dict method on ReturnList type instance to get blocks.
Solution
I have added a type check before fetching blocks if it is getting ReturnList I am treating it as list. otherwise following the old path.
Stacktrace
File "/opened/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response (request)
File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/base.py",line 197, in _get_response
response = wrapped_callback(request,
*callback_args,
**callback_kwargs)
File "/opened/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py",line 56, in wrapper_view return view_func(*args,
**kwargs)
File "/opened/venv/lib/python3.8/site-packages/django/views/generic/base.py",line 104, in view return self.dispatch(request, *args,
**kwargs)
File "/opened/venv/lib/python3.8/site-packages/django/utils/decorators.py",line46,in_wrapper return bound_method(*args
**kwargs)
File "/opened×/venv/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
response = self. handle_exception (exc)
File "/opened/venv/lib/python3.8/site-packages/rest_framework/views.py",line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/opened/venv/lib/python3.8/site-packages/rest_framework/generics.py", line 199, in get return self.list(request, *args, **kwargs)
File "/opened×/edx-platform/./lms/djangoapps/course_api/blocks/views.py", line 315, in list
response = filter_discussion_blocks_from_response(response,
course_key)
File "/opened/edx-platform/./lms/djangoapps/course_api/blocks/utils.py",line19,infilter_discussion_xblocks_from_response key for key, value in response.data.get('blocks' {}).items()
AttributeError:
'ReturnList' object has no attribute
'get'
Thanks for the pull request, @qasimgulzar! Please note that it may take us up to several weeks or months to complete a review and merge your PR.
Feel free to add as much of the following information to the ticket as you can:
- supporting documentation
- Open edX discussion forum threads
- timeline information ("this must be merged by XX date", and why that is)
- partner information ("this is a course on edx.org")
- any other information that can help Product understand the context for the PR
All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.
Please let us know once your PR is ready for our review and all tests are green.
This PR is now ready for review. Cc @vunguyen-dmt who reported the initial issue https://github.com/openedx/edx-platform/issues/34379
@openedx/2u-aperture could you please help reviewing this PR?
Hi @qasimgulzar,
This particular bit of code lies outside of Aperture's ownership/maintenance load, nor does the team have any experience or knowledge of the functionality in the course_api app. I'm afraid we're probably not the best team positioned to help here.
I believe you might be looking for folks from the Aurora team at 2U, who look to be maintainers of this functionality (sorry for any confusion!)
@justinhynes thank you very much for you response, let me try to find someone relevant to this PR. I apologise to bother you :)
@qasimgulzar 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.
2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.
2U Release Notice: This PR has been deployed to the edX production environment.