Skip to content
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

fix: Course blocks API with param return_type=list #34424

Merged
merged 2 commits into from
May 10, 2024

Conversation

qasimgulzar
Copy link
Contributor

@qasimgulzar qasimgulzar commented Mar 26, 2024

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'

@openedx-webhooks
Copy link

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.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Mar 26, 2024
@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Mar 26, 2024
@qasimgulzar qasimgulzar requested a review from a team as a code owner March 27, 2024 11:19
@qasimgulzar qasimgulzar force-pushed the qasim/fix/34379 branch 3 times, most recently from 7927443 to 6d567ba Compare March 28, 2024 10:48
@regisb
Copy link
Contributor

regisb commented Mar 28, 2024

This PR is now ready for review. Cc @vunguyen-dmt who reported the initial issue #34379

@mphilbrick211 mphilbrick211 removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Mar 28, 2024
@qasimgulzar
Copy link
Contributor Author

@openedx/2u-aperture could you please help reviewing this PR?

@justinhynes
Copy link
Contributor

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!)

@qasimgulzar
Copy link
Contributor Author

@justinhynes thank you very much for you response, let me try to find someone relevant to this PR.
I apologise to bother you :)

Copy link
Contributor

@feanil feanil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me other than this, @qasimgulzar do you want to put the imports back as they were? I think the rest of this looks good to land.

Comment on lines 19 to 24
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider
from xmodule.modulestore.tests.django_utils import \
SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order
BlockFactory,
ToyCourseFactory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a weird formatting change, why remove the parens on the first entry and add them to the last one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@feanil I had run iSort on this file but yes it seems weird with / I have manually updated the line and added parentheses. Other than this there were few unused imports do you want me to put those back as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dropping the unused imports is great. This is fine to leave in as-is if this is just weird isort behavior.

@qasimgulzar qasimgulzar requested a review from feanil May 2, 2024 06:56
@feanil feanil merged commit 70f0686 into openedx:master May 10, 2024
66 checks passed
@openedx-webhooks
Copy link

@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.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants