Skip to content

Conversation

@jesusbalderramawgu
Copy link

@jesusbalderramawgu jesusbalderramawgu commented Nov 11, 2025

Description

There's a bug with Numerical Input Component which Incorrectly Handles Formulas as numericalresponse.
after some research and talking with the community we agreed to validate the author block form to just accept numeric values in the answers.

this is how the form will show the error if the value is not numeric.

Screenshot 2025-11-11 at 11 43 47 a m it closes [#1680]

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 11, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @jesusbalderramawgu!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@diana-villalvazo-wgu
Copy link
Contributor

Suggestion: In the description of the PR you can add Fixes #{PR number} or Closes #{PR number} so when this PR is merged the Github issue will be closed automatically

@diana-villalvazo-wgu diana-villalvazo-wgu added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Nov 11, 2025
@diana-villalvazo-wgu diana-villalvazo-wgu moved this from Needs Triage to Ready for Review in Contributions Nov 11, 2025
@jacobo-dominguez-wgu
Copy link
Contributor

You need to follow the conventional commits messages

@bradenmacdonald
Copy link
Contributor

Thanks! Let me know once the other reviewers have approved it, or if you need me to approve some more test runs.

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

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

Thanks for your work so far @jesusbalderramawgu !

);
}
if (problemType !== ProblemTypeKeys.NUMERIC || !answer.isAnswerRange) {
const isValidValue = validateAnswerNumeric(answer.title)
Copy link
Member

Choose a reason for hiding this comment

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

The example formula provided in the "Select Problem Type" modal (m*c^2) is not valid for numeric input:

Screenshot 2025-11-13 at 3 37 35 PM

Here is a valid formula I typed into a numeric problem, and then took a screenshot of:

Screenshot 2025-11-13 at 4 03 58 PM

Unfortunately, it's not visually consistent with the rest of the example problem images in the modal. I'll reach out to see if we can get our hands on the original images... ( @marcotuts , any chance you have access to them?). In the meantime, feel free to use my screenshot, even if it looks a little off.

Copy link
Member

Choose a reason for hiding this comment

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

Marco's working on a new image to put here, will post it here soon~

Copy link
Member

@kdmccormick kdmccormick Nov 14, 2025

Choose a reason for hiding this comment

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

here you go!
numerical_input_illustration

(for future reference: this image and its counterparts are now in the Authoring Figma file)

*/
export const answerRangeFormatRegex = /^[([]\s*-?(?:\d+(?:\.\d+)?|\d+\/\d+)\s*,\s*-?(?:\d+(?:\.\d+)?|\d+\/\d+)\s*[)\]]$/m;

export const numericRegex = /^[+-]?(\d+(\.\d*)?|\.\d+)$/;
Copy link
Member

Choose a reason for hiding this comment

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

Numeric input problems can also include sin, pi, and a few other functions.

I would ask you to reference the docs (https://docs.openedx.org/en/latest/educators/references/course_development/exercise_tools/numerical_input.html), but those docs aren't entirely correct either 🤦🏻 In particular, the docs say that g is allows, but this does not work in practice.

I'll have to do some digging in the code to figure out what's really allowed; I'll circle back. In the meantime, can you try updating the regex to include pi, sqrt, sin, arcscin, cos, arccos, tan, arctan, log2, and parenthases ( ) ?

Copy link
Member

Choose a reason for hiding this comment

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

OK, here's the function which perform the numeric evaluation: https://github.com/openedx/openedx-calc/blob/master/calc/calc.py#L239

And here's the call site: https://github.com/openedx/edx-platform/blob/f4f14a69874d5804ef33778486f7d6cab400e206/xmodule/capa/responsetypes.py#L1563

Note that both variables and unary_functions are passed in as {}.

@jesusbalderramawgu , would you or your team be able to reverse engineer this function in order to figure out exactly what is allowed in a numeric input formula?

Copy link
Author

Choose a reason for hiding this comment

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

sure, I will check this with the team

Copy link
Author

Choose a reason for hiding this comment

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

Hello, just to follow up on the ticket, I'm still checking because now needs more work the validation part.
After this feedback, the frontend shouldn't validate if is a valid math expression, it should be on the backend. After some review I found an endpoint to do this validation but it's really attached to django views, so I'm looking for a way of request this from react and validate the input component.
I'll keep you posted, thanks in advance!

Copy link
Member

Choose a reason for hiding this comment

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

I was also thinking that the validation might need to happen on the backend, glad to see you came to the same conclusion.

Perhaps we need to factor out a new REST API for the validation? Curious to hear what you find.

Copy link
Member

Choose a reason for hiding this comment

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

hey @jesusbalderramawgu , thanks for looking into this. That particular approach is not viable, because we need the editor to be able to work without saving the Problem first. You can see the importance of this by going into Libraries (Beta), creating a Problem, and hitting "Cancel" instead of saving: notice that no Problem is created.

(In Courses, on the other hand, if you being creating a Problem and hit "Cancel", you will end up with a blank problem which you have to then delete. This is an undesirable legacy behavior which we'll want to fix one day.)

I think we'll need a new endpoint, maybe one that just takes an answer string and validates it for a particular response type (formula, numeric, etc.)?

Copy link
Author

Choose a reason for hiding this comment

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

thanks for your feedback @kdmccormick, I checked what you said about the flow and I agree.
a new endpoint is required for this then, it should receive a string and return a boolean to know if is valid or not.
do you know who can help with the creation of this endpoint?

Copy link
Member

@kdmccormick kdmccormick Nov 24, 2025

Choose a reason for hiding this comment

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

@jesusbalderramawgu I'm happy to help. For the ProblemBlock, you can define an endpoint handler by adding a method to the _BuiltInProblemBlock class which takes JSON-friendly data dict as input and return JSON-frienly dict as output. Then, add the method to the handlers dict. The endpoint's URL is the base URL of the block, plus the dict key.

For example, calling:
POST /courses/<course_key>/xblock/<usage_key>/handler/xmodule_handler/problem_check

will look up problem_check in the handlers dict and call the submit_problem method.

Let me know if you could use more pointers, and feel free to book sync time with me if that'd be helpful. https://tinyurl.com/meet-with-kyle

Copy link
Author

Choose a reason for hiding this comment

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

Hello, @kdmccormick, I checked with the team and I just pushed this morning this PR with the new endpoint
openedx/edx-platform#37677
but I see is in a different path and with different approach.
Basically I was thinking in avoid the blockId and courseId, just passing the formula and returning if is valid or not. so we can reuse this in other places if is required.
what do you think about this approach?
what you explained looks good as well I can change it into that approach for sure

Copy link
Author

Choose a reason for hiding this comment

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

I've updated the FE pull request as well, now it works properly. the only thing that is pending is the endpoint.
thanks for your feedback

@mphilbrick211 mphilbrick211 moved this from Ready for Review to In Eng Review in Contributions Nov 13, 2025
@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.86%. Comparing base (36c9eba) to head (f9ce381).
⚠️ Report is 46 commits behind head on master.

Files with missing lines Patch % Lines
...ents/EditProblemView/AnswerWidget/AnswerOption.jsx 88.88% 1 Missing ⚠️
.../editors/containers/ProblemEditor/data/apiHooks.ts 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2615      +/-   ##
==========================================
+ Coverage   94.81%   94.86%   +0.04%     
==========================================
  Files        1225     1234       +9     
  Lines       27481    27963     +482     
  Branches     6187     6360     +173     
==========================================
+ Hits        26056    26526     +470     
+ Misses       1367     1366       -1     
- Partials       58       71      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jesusbalderramawgu jesusbalderramawgu force-pushed the OEXCOM-245/AUTH-BLOCK-FORM-VALIDATION branch from 842e6a2 to 14d2c72 Compare November 15, 2025 00:15
@jesusbalderramawgu
Copy link
Author

You need to follow the conventional commits messages

thanks, I made the change in the current commit messages and I'll keep this in mind for future PR

}));
};

export const validateNumericInput = ({ title, ...rest }) => (dispatch, getState) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

i remember here in authoring in some places they are now using react-query, if its a complete new implementation/endpoint/etc, maybe will be best to use react query from start to avoid the re-work when we move from redux to react-query 🤔

Copy link
Author

Choose a reason for hiding this comment

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

thanks for your comment, I did it this way because this page is really linked to redux and didn't wanna make a mix.
should I change this then to react-query?

Copy link
Member

Choose a reason for hiding this comment

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

I am not an expert here, but I think it could get complex to have a mix of Redux and RQ on the same page, so my inclination is to stay consistent and use Redux when we're just making small additions to existing things. Do you agree @diana-villalvazo-wgu or do you think it'd be better to put his part in RQ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It really depends on the separation of concerns. If this numeric input validation is a fairly isolated piece of code that checks some input value via an API and then displays a message, it's probably pretty easy to implement using React Query and mix-and-match is with redux. But if there are interactions between this validation state and other parts of the existing redux state, then it's probably more trouble than it's worth. Either way is fine with me.

Copy link
Contributor

@diana-villalvazo-wgu diana-villalvazo-wgu Nov 24, 2025

Choose a reason for hiding this comment

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

+1 Same as Braden, i suggested it because i saw that it wasn't really interacting with other things, was a new endpoint call and just appended the result, and just to avoid future re-work, but if it causes any trouble im ok with it too

Copy link
Author

Choose a reason for hiding this comment

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

thanks everyone for your comments. I've updated the PR to use react query instead of redux given that this validation is isolated.
I've made a file called "apiHooks.ts" inside ProblemEditors/Data folder given that the ProblemEditor wasn't using react query and to follow the same nomenclature as the other folders with react query.
the only thing that is left is the change in the API with Kyle's suggestion. I'll check that tomorrow.
thanks for your feedback

Copy link
Member

@kdmccormick kdmccormick Nov 25, 2025

Choose a reason for hiding this comment

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

@jesusbalderramawgu I realized that my validation endpoint suggestion is flawed because it requires that a ProblemBlock be saved :)

I like your approach. I have some thoughts on the details--I'll leave a review tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

regarding the new endpoint, I've left a review on: openedx/edx-platform#37677

@kdmccormick kdmccormick self-requested a review November 24, 2025 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: In Eng Review

Development

Successfully merging this pull request may close these issues.

7 participants