Skip to content

ForEach.not_empty attribute not intuitive; requires workaround #145

@camflint

Description

@camflint

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions