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(utils): omit computedDefault of empty objects #2849
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
907945e
to
828ba9e
Compare
The test I added was explicitly for #2150, I just changed the field names from uuid to EDIT: before my changes the state used to be |
@ranihorev #2150 is about "if object field is not required and left empty then form can be submitted without error". The test is about default values. While the test may indeed reflect the issue, can we add a Form.js-level test that actually steps through the user-level process of this? i.e., it should leave the object field empty, the user should try to submit, there should be no error. Can you also add a test for #2708 so we can see if it fixes that issue too? |
Sure, I misunderstood you earlier, sorry :) |
f2ea45a
to
691f08c
Compare
It was a bit more tricky than I expected, but I added the test (fixed my PR as well). |
691f08c
to
a05bad3
Compare
packages/core/src/utils.js
Outdated
if (includeUndefinedValues || computedDefault !== undefined) { | ||
if ( | ||
includeUndefinedValues || | ||
(typeof computedDefault === "object" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hard to parse. Can we split it into two if statements?
if (typeof computedDefault === "object") {// if statement here}
...
else {// other if statement here }
And also comment out what each branch means
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code. It's more verbose but indeed easier to read.
packages/core/test/utils_test.js
Outdated
}; | ||
expect(getDefaultFormState(schema, {})).eql({}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a test for #2708?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to update the description. I review #2708 and the two issues are identical as far as I can tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So -- that might be correct, but we should still add a test that explicitly tests for the scenario in #2708 -- i.e., tries to perform form validation and then ensures that the validation is working.
@epicfaace when is the next release of package? trying to see if we can get this fix on time :) |
Not sure yet |
👍
And thanks for reviewing the PR!
…On Wed, May 4, 2022 at 16:59 Ashwin Ramaswami ***@***.***> wrote:
@epicfaace <https://github.com/epicfaace> when is the next release of
package? trying to see if we can get this fix on time :)
Not sure yet
—
Reply to this email directly, view it on GitHub
<#2849 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEC2ORONSAJDVY7RD7PLN4LVIMFNLANCNFSM5U7KLQQA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I somehow stashed the Form level tests I wrote instead of pushing them. Sorry about that. |
I think that |
484cb47
to
a6753b5
Compare
@epicfaace I'd love to get your help. I just noticed that my PR could cause a breaking change - if we stop initializing every object to an empty object, we won't be able to set custom errors on nested field (for example, see this). I don't think that it's a big concern for most users, but maybe I'm wrong. We can make it work if we switch from using only the |
@ranihorev So we are actively working on v5 (see the And yes, in order to properly build the schema for custom validation, the |
@heath-freenome thanks for letting me know. I forked the repo so I'm not in a rush. I'll try moving this PR over to |
@ranihorev Sorry for the late reply to your question... no, V4 is locked. You can port your other PR to the v5 branch as well |
@ranihorev Can you port this change, the tests to the |
I can but I'm still not sure how we want to treat custom validations in
this case. What is the expected behavior?
…On Wed, Sep 7, 2022 at 19:36 Heath C ***@***.***> wrote:
@ranihorev <https://github.com/ranihorev> Can you port this change, the
tests to the @rjsf/utils package and also update the CHANGELOG.md?
—
Reply to this email directly, view it on GitHub
<#2849 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEC2ORLCT73EP5RHMBOTTELV5DACPANCNFSM5U7KLQQA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@epicfaace Do you have an opinion? |
@ranihorev Here is what I propose... In both of the validators, let's try moving
to right before the I've sanity checked the tests with that change and it seems to work. Then make your change in the utils so that it continues to respect the |
Sorry, I'm not clear what you're asking? |
@epicfaace Check out my proposal in comments above |
@heath-freenome to make sure we're on the same page: you are suggesting to run I wonder if we should call |
There is some sense to that as well... Go with that. |
a6753b5
to
e516a7f
Compare
I started without computing it twice. It works great in the UI, but it breaks a lot of tests in utils as they all assume (incorrectly IMO) that those nested default objects will be generated. My plan is to fix them by manually setting |
e516a7f
to
38044a6
Compare
I found a bug in my PR :(
I'll look for a solution, but if anyone has an idea, please let me know :) |
Nothing comes to mind at the moment :( |
I used this PR as a starting point to make my own: #3287 |
Thanks for picking this up! |
This was fixed in #3287 |
Reasons for making this change
Fixes #2150 and #2708.
See this playground
If there are no defaults,
computedDefault
will still create an empty object here. As a result, ajv assumes that the field should exist and is failing the validation if it has any required fields.