Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ForEach.not_empty attribute not intuitive; requires workaround #145

Copy link
Copy link
@camflint

Description

@camflint
Issue body actions

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?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.