Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for multiple tags in url #2558

Closed
ossark opened this issue Nov 7, 2018 · 7 comments
Closed

Search for multiple tags in url #2558

ossark opened this issue Nov 7, 2018 · 7 comments
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@ossark
Copy link

ossark commented Nov 7, 2018

Environment

  • Python version: 2.7.10
  • NetBox version: 2.4.4

Proposed Functionality

It would be nice to be able to search for multiple tags (or other keywords) like so:
https://netbox/api/ipam/prefixes/?tag=vpn1&tag=vpn2

This should yield a list of items that matches both tags. Currently the above URL only returns the items that match tag"vpn2".

Use Case

If one has multiple customers and wants a list of resources that affects a few specific customers this could come in handy. Also, if you want to highlight prefixes that are link nets between sites, tags are appropriate to find the link nets that span over two (or more) specific sites.

Database Changes

External Dependencies

@jeremystretch
Copy link
Member

I'm marking this as a bug (as opposed to a feature request) as I think it's reasonable to expect that tags should work this way already.

As for the implementation, there's some discussion around different approaches here, but we'll probably just make a custom TagFilter() to be reused across all models.

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Nov 7, 2018
@ossark
Copy link
Author

ossark commented Nov 8, 2018

If one would like it to be OR instead of AND. How would that me modelled? I am also seeing a case where you would want to list the items that match tag "vpn1" OR "vpn2" in a single call. I prefer the AND notation though. Not sure what is customary in REST.

@jeremystretch
Copy link
Member

jeremystretch commented Nov 8, 2018

The behavior exhibited by existing filters is OR. For example, /devices/?site=foo&site=bar will return devices from either site. (The problem with the tag filter is that only the last tag specified in a list is being considered.)

I don't think there's any inherent mechanism for implying OR vs AND in django-filter.

@ossark
Copy link
Author

ossark commented Nov 8, 2018

I understand. What I would prefer for the "?tag=" filter is AND.

What about using the ?tag=vpn1,vpn2 construct to indicate AND?

@jeremystretch
Copy link
Member

I've implemented this with the AND logic, such that ?tag=foo&tag=bar will return only objects with both tags assigned.

@alimoghrabi
Copy link

Is this functionality working properly? I have tested it in my environment and it doesn't seem to be returning the correct data.

@ossark
Copy link
Author

ossark commented Apr 24, 2019 via email

@lock lock bot locked as resolved and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants