Skip to content

Add a length assertion on FilterSets #239

@thclark

Description

@thclark

Feature request

Use Case

I want to be sure that after applying filters, I want to validate that I have a certain number of files.

For example, if I'm expecting a dataset to contain separate files for U, V, W components of a velocity field, I expect to get three files. Maybe I'd do:

filtered = my_dataset.files.filter(name__ends_with=".asc").filter(any_label_contains="component").order_by("tags__component")

But I'll always need to know there'll be three files.

Current state

I'll do:

assert(len(filtered) == 3)

However, I think it'd be neater to have an assertion built in, like:

my_dataset.files.filter(name__ends_with=".asc").filter(any_label_contains="component").order_by("tags__component").assertNumberOfFiles(3)

That way we could ultimately handle the exception and raise it as the same kind of validation error as we get e.g. if the input_values don't validate, so to an external user of the child, validation errors appear unified.

Metadata

Metadata

Assignees

Labels

decision neededA decision is required (e.g. on UX or company policy)

Type

No type

Projects

Status

Priority 2 (Medium)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions