sphinx-needs icon indicating copy to clipboard operation
sphinx-needs copied to clipboard

filter-func ignores other filter options on directive

Open twodrops opened this issue 2 years ago • 2 comments

The following filter filters elements with ID "MY_ELEMENT_01" and further filters it with the types. In the end only elements of type "req-sys" and ID "MY_ELEMENT_01" shall be shown.

.. needtable::
   :style: table
   :types: req-sys
   :filter: ID == "MY_ELEMENT_01"

If the same is written using filter-func, the types is fully ignored and all elements filtered by filter-func are displayed.

.. needtable::
   :style: table
   :types: req-sys
   :filter-func: filter_element_by_id

I guess the problem might be present in all sphinx-needs directives where filter-func is used.

twodrops avatar Oct 23 '22 05:10 twodrops

To be honest, I'm not sure what the expected behavior is. My personal opinion was, if you use a filter-string, you don't use the other mechanisms anymore. I didn't even know that this is possible :)

But I agree that the behavior should be the same for a combination of the standard ways with filter-string or filter-func. So I agree, that for filter-func the other filters should be used as some kind of a pre-filter and the result shall then be given to the filter-func as input.

Just for the theory, should this be also possible?

.. needtable::
   types: req
   :filter: status == "open"
   :filter-func: my_filter_funcy

So using nearly every filter possibility....

danwos avatar Oct 24 '22 06:10 danwos

My usecase is, I have a filter-func which filters based on a particular logic. If I now want to filter by type, I need to pass an additional argument to the filter-func. I am already having some problems with arguments in filter-func.

I would probably set filter and filter-func as mutually exclusive. Theoretically, it is possible to have both, but I am not sure if the order of filtering will be clear to users.

twodrops avatar Oct 24 '22 07:10 twodrops