Closed sdoiron0330 closed 7 months ago
The only way I can think to solve this right now is replacing the subquery with something that would take the form of this query, but I couldn't figure out the right way in the Django ORM to do that so I thought I'd ask here first before diving more into it:
select location.name, count(location.name)
from dcim_inventoryitem parts
join dcim_device device on parts.device_id = device.id
join dcim_location location on device.location_id = location.id
group by location.name
Thanks @sdoiron0330 . Issue appears to be connected to the Nautobot 2.0 migrating to use TreeQuerySet
for some of the models. This breaks the removal of default ordering with order_by()
and consequently breaks the expected behavior of the annotate
when used with values
.
My client confirmed that they were also seeing a similar error in their Nautobot 1.6 instance today. I haven't dove into that as I'm actively working on upgrading them, but let me if those same reproduction steps causes the same issue locally.
Perhaps this was in place longer than we thought but it is connected to the InventoryItem
QuerySet using TreeQuerySet
class which doesn't play nicely with the default order_by()
. I've applied fix in my local environment and it seems to be working. I will do some more testing and will get a PR raised.
Pulled your branch locally and the metrics looked to be working correctly. Similar results within my client's environment. Appreciate the quick turnaround on this!
That's great! I'll get the PR in today.
Environment
Expected Behavior
When the post_upgrade command is run before server start up, no errors occur. When you load the
localhost/metrics
endpoint, Prometheus metric data is populated.Observed Behavior
The following error occurs (line 217 of DLM, metrics_lcm_hw_end_of_support):
Steps to Reproduce
nautobot-server post_upgrade
or loadlocalhost/metrics
.