-
-
Notifications
You must be signed in to change notification settings - Fork 360
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
[BUG] Nested required attribute is enforced, even when optional parent is not defined #900
Comments
@ebrearley Few things:
Now on to the main topic. I thought about this a lot. I could have SWORN I considered this a lot and had a reason for everything I implemented when it comes to this. The goal was to have it so that you could have a lot of flexibility and to where anything was possible here. This does sound like a bug to me, since it doesn't achieve those principles. There is no way to have a sub property required only if the parent exists. If you want both to be required, you can set I'm pretty sure that summarizes my goal of what this should be. I don't think there are any other edge cases to consider here. I will add this to the todo list, and try to reproduce it and look into it more. |
Yes, can confirm, this absolutely summarises everything I'd like to be able to do. |
Up to you. It might be useful for others. But then my comment might get confusing since it's unclear what I was referring to. Maybe adding a warning with a link to my comment about why it's a bad idea? At this point I've done all I can to mention that it's a bad idea. If you wish to help communicate that more, that'd be great. But I've done all I can haha. If you'd like you can look into creating a pull request for this. I'm really focusing on some of the single table design things currently. I'm almost done with 1 of the 5 urgent single table design features I want to do. Hoping to speed up the development on that, and hopefully get that out ASAP. Otherwise, I'll get around to this when I can. Thanks for the report tho! |
I thought I'd give knocking up a PR for you a crack and I stumbled onto something that looks a lot like it does exactly what we want it to do: Lines 371 to 394 in e70f5ca
You weren't wrong, you've definitely given this a lot of thought! You've even implemented logic that reflects the intended behaviour. So I turned my focus towards the schema in my application to figure our what's going on. And I've found the culprit: A
|
@ebrearley Without thinking about it much, yes, |
@ebrearley What is the status on this? Any chance you look into creating a PR? |
Summary:
Let's say that I have a store that sells two products, apples and boxes and I define the cart item schema like this:
Schema
The application does two things with this schema:
appleAttribues
is defined when the type isAPPLES
boxAttributes
is defined when the type isBOX
Neither
appleAttribues
orboxAttributes
are required, but they themselves have required attributes.The problem
We cannot leave
boxAttributes
undefined without getting the following validation error:same goes for leaving
appleAttribues
undefined.What I think the behaviour should be
Only run
required
validation checks on an item that has it's parent value defined.Environment:
Operating System:
MacOS
Operating System Version:
10.14.6 Mojave
Node.js version (
node -v
):12.14.1
NPM version: (
npm -v
):6.13.4
Dynamoose version:
2.1.2
Other:
The text was updated successfully, but these errors were encountered: