API count shows count of all aggregate tagged items and not count of tags #2650

Closed
opened 2025-12-29 18:20:52 +01:00 by adam · 6 comments
Owner

Originally created by @pm17788 on GitHub (Jun 4, 2019).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.5.13

Steps to Reproduce

  1. Browse to: https://NetBoxURL/extras/tags, see count of tags (ex: 25)
  2. Browse to: https://NetBoxURL/api/extras/tags, see count which is an aggregate of all tagged items, rather then the count of distinct tags in NetBox

Expected Behavior

API count of tags should match the WebUI and the API

Observed Behavior

API count of tags doesn't match the WebUI, or the behavior of count variable on other API endpoints.

Originally created by @pm17788 on GitHub (Jun 4, 2019). ### Environment * Python version: 3.5.2 * NetBox version: 2.5.13 ### Steps to Reproduce 1. Browse to: https://NetBoxURL/extras/tags, see count of tags (ex: 25) 2. Browse to: https://NetBoxURL/api/extras/tags, see count which is an aggregate of *all* tagged items, rather then the count of distinct tags in NetBox ### Expected Behavior API count of tags should match the WebUI and the API ### Observed Behavior API count of tags doesn't match the WebUI, or the behavior of `count` variable on other API endpoints.
adam added the type: bugstatus: accepted labels 2025-12-29 18:20:52 +01:00
adam closed this issue 2025-12-29 18:20:53 +01:00
Author
Owner

@DanSheps commented on GitHub (Jun 4, 2019):

Confirmed this is still present.

This looks to be to do with some performance optimizations made in the Pagination class.

@DanSheps commented on GitHub (Jun 4, 2019): Confirmed this is still present. This looks to be to do with some performance optimizations made in the Pagination class.
Author
Owner

@KhaledTo commented on GitHub (Jun 4, 2019):

If my understanding is correct the count in /api/extras/tags should show the number of distinct tags like in /extras/tags.

I can take this, except if @pm17788 you want to work on this fix.

@KhaledTo commented on GitHub (Jun 4, 2019): If my understanding is correct the count in ` /api/extras/tags` should show the number of distinct tags like in `/extras/tags`. I can take this, except if @pm17788 you want to work on this fix.
Author
Owner

@pm17788 commented on GitHub (Jun 5, 2019):

@KhaledTo : Sadly, my Python-Fu is still weak. Still learning, so I'm not ready to go committing code yet.

@pm17788 commented on GitHub (Jun 5, 2019): @KhaledTo : Sadly, my Python-Fu is still weak. Still learning, so I'm not ready to go committing code yet.
Author
Owner

@jeremystretch commented on GitHub (Jun 5, 2019):

Looks like I fixed a slightly different problem under #3116.

FYI this has already been fixed under develop-2.6. The root issue stems from the use of distinct=True when annotating the TaggedItem count on the queryset. In v2.6, we've started using subqueries instead.

Not sure it makes sense to backport this utility function to the v2.5 train but we should be able to do a one-off implementation.

@jeremystretch commented on GitHub (Jun 5, 2019): Looks like I fixed a slightly different problem under #3116. FYI this has already been fixed under `develop-2.6`. The root issue stems from the use of `distinct=True` when annotating the TaggedItem count on the queryset. In v2.6, we've started using [subqueries](https://github.com/digitalocean/netbox/blob/develop-2.6/netbox/utilities/utils.py#L75) instead. Not sure it makes sense to backport this utility function to the v2.5 train but we should be able to do a one-off implementation.
Author
Owner

@pm17788 commented on GitHub (Jun 5, 2019):

@jeremystretch : If it is not too tricky to make into 2.5 branch, it'd be awesome. There is some code I'd like to roll out internally, and can't, because of this silly thing :(

@pm17788 commented on GitHub (Jun 5, 2019): @jeremystretch : If it is not too tricky to make into 2.5 branch, it'd be awesome. There is some code I'd like to roll out internally, and can't, because of this silly thing :(
Author
Owner

@jeremystretch commented on GitHub (Jun 20, 2019):

Closing this out as v2.6 is being released today.

@jeremystretch commented on GitHub (Jun 20, 2019): Closing this out as v2.6 is being released today.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2650