-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
oneOf/anyOf array item incorrectly selected despite not valid against data, once it has at least two oneOf/anyOf properties itself #3693
Comments
@michal-kurz Another good catch. You'd think we'd have oneOf/anyOf nailed down by now, but nope. Turns out it's a hard nut to crack. Have you figured out where the issue is occurring? I noticed you have already dug into the performance issue. This one is simpler and could be fixed more easily. |
I believe I found the issue but haven't come up with the best solution yet. The root cause is in AnyOfField.getMatchingOption. Basically The logic is assuming that index 0 means it didn't match a schema but in reality it does. I have been playing around with a solution removing that check and always taking the index returned by |
@cwendtxealth @michal-kurz Wow, what a subtle little bug. I think that making the following change would solve this issue:
Feel free to test it out and if it does work provide a PR! Thanks! |
@heath-freenome I tried out that solution and its still happening. It is still returning the valid option of index |
Prerequisites
What theme are you using?
core
Version
5.7.2
Current Behavior
Schema:
Data:
Result: "Foo" item is selected in UI
Expected Behavior
"Bar" item being selected in UI
Steps To Reproduce
Open this sandbox: https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6W3sidHlwZSI6ImJhciJ9XSwic2NoZW1hIjp7InR5cGUiOiJhcnJheSIsInRpdGxlIjoiVGVzdCIsIml0ZW1zIjp7Im9uZU9mIjpbeyJ0eXBlIjoib2JqZWN0IiwidGl0bGUiOiJGb28iLCJwcm9wZXJ0aWVzIjp7InR5cGUiOnsidHlwZSI6InN0cmluZyIsImVudW0iOlsiZm9vIl0sImRlZmF1bHQiOiJmb28ifSwiYWFhIjp7InR5cGUiOiJvYmplY3QiLCJhbnlPZiI6W119LCJiYmIiOnsidHlwZSI6Im9iamVjdCIsImFueU9mIjpbXX19fSx7InR5cGUiOiJvYmplY3QiLCJ0aXRsZSI6IkJhciIsInByb3BlcnRpZXMiOnsidHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwiZW51bSI6WyJiYXIiXSwiZGVmYXVsdCI6ImJhciJ9fX1dfX0sInVpU2NoZW1hIjp7ImZpcnN0TmFtZSI6eyJ1aTphdXRvZm9jdXMiOnRydWUsInVpOmVtcHR5VmFsdWUiOiIiLCJ1aTpwbGFjZWhvbGRlciI6InVpOmVtcHR5VmFsdWUgY2F1c2VzIHRoaXMgZmllbGQgdG8gYWx3YXlzIGJlIHZhbGlkIGRlc3BpdGUgYmVpbmcgcmVxdWlyZWQiLCJ1aTphdXRvY29tcGxldGUiOiJmYW1pbHktbmFtZSJ9LCJsYXN0TmFtZSI6eyJ1aTphdXRvY29tcGxldGUiOiJnaXZlbi1uYW1lIn0sImFnZSI6eyJ1aTp3aWRnZXQiOiJ1cGRvd24iLCJ1aTp0aXRsZSI6IkFnZSBvZiBwZXJzb24iLCJ1aTpkZXNjcmlwdGlvbiI6IihlYXJ0aCB5ZWFyKSJ9LCJiaW8iOnsidWk6d2lkZ2V0IjoidGV4dGFyZWEifSwicGFzc3dvcmQiOnsidWk6d2lkZ2V0IjoicGFzc3dvcmQiLCJ1aTpoZWxwIjoiSGludDogTWFrZSBpdCBzdHJvbmchIn0sInRlbGVwaG9uZSI6eyJ1aTpvcHRpb25zIjp7ImlucHV0VHlwZSI6InRlbCJ9fX0sInRoZW1lIjoiZGVmYXVsdCIsImxpdmVTZXR0aW5ncyI6eyJzaG93RXJyb3JMaXN0IjoidG9wIiwidmFsaWRhdGUiOmZhbHNlLCJkaXNhYmxlZCI6ZmFsc2UsIm5vSHRtbDVWYWxpZGF0ZSI6ZmFsc2UsInJlYWRvbmx5IjpmYWxzZSwib21pdEV4dHJhRGF0YSI6ZmFsc2UsImxpdmVPbWl0IjpmYWxzZSwiZXhwZXJpbWVudGFsX2RlZmF1bHRGb3JtU3RhdGVCZWhhdmlvciI6eyJhcnJheU1pbkl0ZW1zIjoicG9wdWxhdGUifX19
Environment
No response
Anything else?
"foo" must have two or more anyOf/oneOf properties for this to happen
The text was updated successfully, but these errors were encountered: