Skip to content

FilterCondition should allow filtering over attributes as well as annotations #1800

@carlashworth

Description

@carlashworth

The current behaviour of filtering using the FilterCondition class (#1068) is to check if the key whose value is being filtered is in object annotations:

if isinstance(value, filters.FilterCondition) and key in obj.annotations:
                    if value.evaluate(obj.annotations[key]):
                        results.append(obj)
                        break

However, this means that attributes such as Event.name cannot be filtered using FilterConditions, which would be useful, e.g. when filtering out two types of event by name using the IsIn FilterCondition.

To solve this problem, I added a second if statement below to check for the key in the object attributes, e.g:

                if isinstance(value, filters.FilterCondition) and key in obj.annotations:
                    if value.evaluate(obj.annotations[key]):
                        results.append(obj)
                        break
                # Add this
                if isinstance(value, filters.FilterCondition) and hasattr(obj, key):
                    if value.evaluate(getattr(obj, key)):
                        results.append(obj)
                        break

Other alternatives such as allowing multiple targdicts both with a "name" attribute do not appear to work currently- and this is what FilterCondition is designed to avoid. Additionally, get_events does not seem to support multiple values for a single attribute, as it checks each event in the Event object for equivalence if multiple values are passed. (Also relevant might be #761 about adding AND and OR functionality)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions