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

ForEach.not_empty attribute not intuitive; requires workaround #145

Open
camflint opened this issue Dec 22, 2018 · 0 comments
Open

ForEach.not_empty attribute not intuitive; requires workaround #145

camflint opened this issue Dec 22, 2018 · 0 comments

Comments

@camflint
Copy link

I have a custom schema that looks like the following.

class NewOrderSchema(Schema):
    customer_id = CustomerEntity()
    order_items = ForEach(OrderItemSchema(), if_missing=NoDefault, not_empty=True)
    payment_method_id = Int(min=0, if_empty=0)
    status_id = Int(min=0, if_empty=0)
    notes = String(if_empty='')
    return_url = String(if_empty='/')

The problematic line is this one:

    order_items = ForEach(OrderItemSchema(), if_missing=NoDefault, not_empty=True)

The intent I'm trying to express in the schema is that I should NOT receive an empty list of nested OrderItemSchemas.

I find that in order for this to work, I must specify the if_missing=NoDefault keyword argument in addition to not_empty=True. It took me a long time to figure this out, since I assumed that passing not_empty=True to ForEach() would be sufficient.

Is this behavior intended? If so, could we document it better?

@camflint camflint changed the title ForEach.not_empty attribute not intuitive; requires workaround ForEach.not_empty attribute not intuitive; requires workaround Dec 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant