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

Create a runtime service for answer_available function #33424

Closed
wants to merge 16 commits into from

Conversation

steff456
Copy link

@steff456 steff456 commented Oct 5, 2023

Description

This PR fixes #33325

This PR,

  • Refactors the function answer_available to reduce the logic shown for each XBlock authors.
  • It doesn't change any of the logic that was previously defined.

Supporting information

Testing instructions

  • Checkout to the current branch and build devstack
  • Browse the demo course to Content > Outline and search the Homework task
  • Pick any of the activities in the live and studio version and use the show answer button

Deadline

None

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 5, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Oct 5, 2023

Thanks for the pull request, @steff456! 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.

Copy link
Contributor

@Cup0fCoffee Cup0fCoffee left a comment

Choose a reason for hiding this comment

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

@steff456 It is a good start, but I don't think it's quiet it.

First of all, testing instructions should usually provide manual steps which can be performed to test the changes. It can be challenging to do for the refactoring PRs, since the goal is for the behavior to stay the same. I would suggest, creating a few problem blocks through the studio in the demo course, set different ShowAnswer values, and test that all of the behave the same before the refactor and after. Then you can add these steps, so that the review can both - see if the testing steps are sufficient, and try them himself to validate the changes.

Second, is that I can see that David mentioned that it should be refactored into a runtime service:

We should refactor this into a runtime service that will return a simple True/False for this question, so that we can get consistent behavior without other XBlock authors having to think about it.

To be frank, I'm not super familiar with the internals of the XBlocks. However, I know that the way that XBlocks can access services from XBlock runtime is via self.runtime.service(.... I grepped for def service\( and can see it in a few places, but the most notable is in openedx/core/djangoapps/xblock/runtime/runtime.py on line 231. You'll be able to see that this method returns many different services, and my intuition suggests that the new service should be implemented in the similar way as those, and returned from that method. Don't be afraid to let David know on the issue that you're working on it, and you can as well ask him what he thinks about this approach. IIRC, he knows the internals of the XBlocks well.

@mphilbrick211
Copy link

Hi @steff456! Thanks for this contribution! Please let me know if you have any questions regarding submitting the CLA form. Thanks!

@mphilbrick211 mphilbrick211 added needs test run Author's first PR to this repository, awaiting test authorization from Axim and removed needs test run Author's first PR to this repository, awaiting test authorization from Axim labels Oct 6, 2023
@e0d e0d added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Oct 10, 2023
Copy link
Contributor

@Cup0fCoffee Cup0fCoffee left a comment

Choose a reason for hiding this comment

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

As David commented here, it seems like these services need to be added in other places as well.

This is looking much closer to the final solution. A few other things are:

  • Can you please sign the CLA mentioned in this comment?
  • I see that Ed has pushed a commit, probably to trigger the pipelines. As you can see some of the pipelines that ran are failing, including some code linting, commit message linting and some unittests that haven't been updated with the changes. Can you please make sure you address those?

xmodule/capa_block.py Outdated Show resolved Hide resolved
xmodule/graders.py Outdated Show resolved Hide resolved
@mphilbrick211 mphilbrick211 added needs test run Author's first PR to this repository, awaiting test authorization from Axim and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Oct 11, 2023
Copy link
Contributor

@Cup0fCoffee Cup0fCoffee left a comment

Choose a reason for hiding this comment

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

@steff456

First of all, I can see that some of the tests are failing. Since the github actions are blocked, you will need to run the tests locally. You can do that by going to the devstack directory, then running make lms-shell and inside the shell you can run pytest -vvv -p no:randomly xmodule to run the tests for xmodule. You should run other tests as well by removing xmodule or changing it to a path , but that might take a lot of time, so do it only once you think that most of the issues have been addressed.

You will at the very least need to add @XBlock.wants('show_correctness') and @XBlock.wants('show_answer') decorators to the XBlock classes that use the new services (only add where appropriate), like ProblemBlock. In other tests the runtime doesn't return the service, so you probably need to add it to the xmodule/tests/__init__.py to get_test_system and prepare_block_runtime functions.. This will fixed most, but not all tests that are failing.

You would also want to run some linters. You can do in the similar way, by calling paver run_pep8 and paver run_pylint it should catch most issues.

Secondly, I think the tests that are testing the new services, but are still located in the xmodule/tests/test_graders.py should be moved to the appropriate xmodule/tests/test_services.py.

The PR description is still missing the testing instructions.

Lastly, can you please rebase your branch onto master instead of merging the master branch into your branch. This should make commit history cleaner. You should make sure that your commit messages follow the conventional commits format. You can also squash your commits into one or several, if more appropriate.

xmodule/services.py Outdated Show resolved Hide resolved
xmodule/tests/test_capa_block.py Outdated Show resolved Hide resolved
xmodule/services.py Outdated Show resolved Hide resolved
xmodule/services.py Outdated Show resolved Hide resolved
xmodule/capa_block.py Outdated Show resolved Hide resolved
@steff456
Copy link
Author

@Cup0fCoffee thanks for the detailed review!

I already ran locally all the tests and they are working as expected. I also checked the linting, pep8 doesn't flagged any issue, but there's a lot of unrelated linting errors coming from files that I didn't modified in this PR from the pylint check.

Also, I already left the testing instructions in the details of this PR and made the rebase.

Please let me know if there's anything else I need to check before this PR is ready!

@Cup0fCoffee
Copy link
Contributor

👍

  • I tested this: I've used the various blocks from homework sections of the demo course, changed the show answer and show correctness values, and tested that they work as expected
  • I read through the code
  • [n/a] I checked for accessibility issues
  • [n/a] Includes documentation

@mphilbrick211 mphilbrick211 removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Oct 17, 2023
@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Oct 19, 2023
Copy link
Member

@Agrendalath Agrendalath left a comment

Choose a reason for hiding this comment

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

It's not a full review - I was just passing by.

cms/djangoapps/contentstore/utils.py Outdated Show resolved Hide resolved
xmodule/services.py Show resolved Hide resolved
xmodule/services.py Outdated Show resolved Hide resolved
xmodule/services.py Outdated Show resolved Hide resolved
xmodule/graders.py Show resolved Hide resolved
@mphilbrick211 mphilbrick211 removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Oct 23, 2023
@open-craft-grove
Copy link

Sandbox deployment started.

@open-craft-grove
Copy link

Sandbox deployment successful.

Sandbox LMS is available at pr-33424-139931.staging.do.opencraft.hosting
Sandbox Studio is available at studio.pr-33424-139931.staging.do.opencraft.hosting

@open-craft-grove
Copy link

Sandbox update request received. Deployment will start soon.

@open-craft-grove
Copy link

Sandbox deployment started.

@open-craft-grove
Copy link

Sandbox update request received. Deployment will start soon.

@ormsbee
Copy link
Contributor

ormsbee commented Nov 30, 2023

@steff456: Please let me know if you're blocked on anything else. Thank you!

@e0d e0d removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Nov 30, 2023
@e0d
Copy link
Contributor

e0d commented Nov 30, 2023

@steff456 there are some test failures. Can you have a look? I've added you to the triage group, so the tests should run automatically going forward.

@open-craft-grove
Copy link

Sandbox deployment failed.

Check failure logs here https://grove-stage-build-logs.nyc3.digitaloceanspaces.com/34602668-5658336475.log

Instance config : https://grove-stage-build-logs.nyc3.digitaloceanspaces.com/34602668-5658336475-config.yml
Instance requirements : https://grove-stage-build-logs.nyc3.digitaloceanspaces.com/34602668-5658336475-requirements.txt

Please check the settings and requirements and retry deployment by updating the pull request or posting a /grove sandbox update comment.

@steff456 steff456 self-assigned this Dec 1, 2023
@steff456
Copy link
Author

steff456 commented Dec 1, 2023

@e0d thanks for adding me!

@ormsbee @Agrendalath I already made the final changes. At the end I moved a lot of functions to the service as requested. Hope this PR is ready for a final review and hopefully approval :)!

Let me know if there's anything else as always

Copy link
Contributor

@ormsbee ormsbee left a comment

Choose a reason for hiding this comment

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

Almost there–just a couple of issues with the tests modified. Thank you.

xmodule/tests/test_capa_block.py Outdated Show resolved Hide resolved
xmodule/tests/test_capa_block.py Outdated Show resolved Hide resolved
xmodule/services.py Outdated Show resolved Hide resolved
xmodule/services.py Outdated Show resolved Hide resolved
@steff456
Copy link
Author

steff456 commented Dec 9, 2023

Hi @ormsbee! Thanks for the review, I just made the changes requested. Please note that the bugs I encountered will yield into failing tests. From what I understood from our previous discussion is that fixing those tests is out of scope for this PR, so please let me know what else is missing for having the approval and merge of this PR.

@steff456
Copy link
Author

steff456 commented Jan 3, 2024

@ormsbee I hope you had a great time during holidays! I wanted to ping just to know what else is needed for this PR to be approved?

@ormsbee
Copy link
Contributor

ormsbee commented Jan 5, 2024

Thank you for the reminder. It looks good. I'll merge on Monday.

@steff456
Copy link
Author

Hi @ormsbee I'm pinging again to ask what else is needed from this PR to be approved, thanks!

@ormsbee
Copy link
Contributor

ormsbee commented Jan 24, 2024

@steff456: Just squash your commits and you're good. I just cannot merge this and monitor it rolling out this week because of other time commitments. @Cup0fCoffee: If an OpenCraft CC wants to do so, please feel free. FYI to @connorhaugh: this is a refactoring how how capa problems generate various "show answer" statuses (refactor into a service).

@Cup0fCoffee
Copy link
Contributor

@ormsbee Thank you. I'll check with the team.

@Cup0fCoffee
Copy link
Contributor

@ormsbee FYI, Piotr agreed to merge it some time in the next two weeks.

@Cup0fCoffee
Copy link
Contributor

@steff456 @ormsbee @Agrendalath This PR should be closed in favor of #34320, because this PR was open from a fork that doesn't allow us to squash and rebase the commits.

@Agrendalath Agrendalath closed this Mar 1, 2024
@openedx-webhooks
Copy link

@steff456 Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future.

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.

Create XBlock permissions for can_view_answer, can_view_correctness
8 participants