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

Backend Validation for Questions #8646

Closed
crphang opened this issue Mar 15, 2018 · 7 comments
Closed

Backend Validation for Questions #8646

crphang opened this issue Mar 15, 2018 · 7 comments
Labels
a-Storage Database schema, Datastore-related technologies/quirks c.Task Other non-user-facing works, e.g. refactoring, adding tests

Comments

@crphang
Copy link
Contributor

crphang commented Mar 15, 2018

Currently when adding new questions, a sample data flow works like this.

In InstructorFeedbackQuestionAddAction

FeedbackQuestionAttributes feedbackQuestion = extractFeedbackQuestionData(instructorDetailForCourse.email);
List<String> questionDetailsErrors = feedbackQuestion.getQuestionDetails().validateQuestionDetails();

In extractFeedbackQuestionData:

  1. It calls extractQuestionDetails, which already does a validation of the fields, and add to the instance variable.
  2. It then serialises those instance variables and store it as Text/Json.

From feedbackQuestion.getQuestionDetails().validateQuestionDetails();:

It picks up the fields that in the metadata, and validates them, returning errors to the user when appropriate. There are a few issues with this flow.

When extractQuestionDetails realises that the fields are invalid, it can do a few things:

  1. Put a dummy value to be stored in metaData that signals that an error occured, or leave it null. Then in validateQuestionDetails, we pick up this dummy value and know its an error and tell the user.
  2. Simply store the invalid value and allow the validation to be done in validateQuestionDetails and let the user know of the errors.

Both techniques are not perfect due to the coupling between store persistence, extractQuestionDetails and validateQuestionDetails. An implementation that could work is to allow extractQuestionDetails to return the errors since it's already doing the validation, after all, invalid fields should not be permeated in the database.

@crphang crphang added s.ToInvestigate The issue sounds complete but needs validation by a core team member a-Storage Database schema, Datastore-related technologies/quirks c.Task Other non-user-facing works, e.g. refactoring, adding tests and removed s.ToInvestigate The issue sounds complete but needs validation by a core team member labels Mar 15, 2018
@shaharyar-shamshi
Copy link
Contributor

shaharyar-shamshi commented Mar 20, 2018

@crphang sir As I am able to understand that
FeedbackQuestionAttributes feedbackQuestion = extractFeedbackQuestionData(instructorDetailForCourse.email); first assign the value to the newQuestion then validate it, we have to just validate it before assigning

@crphang
Copy link
Contributor Author

crphang commented Mar 20, 2018

Based on current design:

  1. It assigns a false value, and validate by returning the error message to the user.
  2. Or it does not assign any value if field is incorrect, but no appropriate error messages can be shown to the user.

What we can do is let extractQuestionDetails/extractFeedbackQuestionData return the error messages and do validation at the same time. This involves refactoring the questions as well as the controller.

@shaharyar-shamshi
Copy link
Contributor

@crphang sir for each type of question there is their different individual error message which is generated after validating from List<String> questionDetailsErrors = feedbackQuestion.getQuestionDetails().validateQuestionDetails();

@crphang
Copy link
Contributor Author

crphang commented Mar 20, 2018

@shaharyar-shamshi yes. But validateQuestionDetails, if you inspect its implementation, validateQuestionDetails does validation by checking the meta data, which means the data is already serialized. But problem is, data that is invalid should not be placed in the database in the first place.

And yes, refactoring involves changing all the validateQuestionDetails for all question types.

@shaharyar-shamshi
Copy link
Contributor

@crphang sir should we also throw null parameter error to the user when particular field(if required) is empty empty.

@crphang
Copy link
Contributor Author

crphang commented Mar 20, 2018

@shaharyar-shamshi, this is left to each question's design of validation. I believe we will add that into the error list to be displayed to user. To clarify further, this issue is more about refactoring the flow of how validation is done, than what the validation is and should be specifically for each question.

@xpdavid
Copy link
Contributor

xpdavid commented Aug 13, 2020

In V7, there is no extractQuestionDetails. *QuestionDetails will be deserialized from JSON (same effect as extractQuestionDetails but more systematically) and validateQuestionDetails will be called. In other word, the deserialization does not do validation, only validateQuestionDetails will do so.

@xpdavid xpdavid closed this as completed Aug 13, 2020
@wkurniawan07 wkurniawan07 removed this from the V7.X.0 milestone Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-Storage Database schema, Datastore-related technologies/quirks c.Task Other non-user-facing works, e.g. refactoring, adding tests
Projects
None yet
Development

No branches or pull requests

4 participants