Cached REST API spec introduced in #6423 is stale after updates #6350

Closed
opened 2025-12-29 19:39:43 +01:00 by adam · 2 comments
Owner

Originally created by @fabi125 on GitHub (Apr 13, 2022).

Originally assigned to: @kkthxbye-code on GitHub.

NetBox version

v3.1.11

Python version

3.8

Steps to Reproduce

  1. Install Netbox v3.0.5+
  2. Fetch http://netbox/api/docs/?format=openapi to populate Redis cache
  3. Update to another Netbox version.
  4. Fetch http://netbox/api/docs/?format=openapi and get the old openapi definition

Expected Behavior

The correct openapi definition should be returned.

Observed Behavior

Stale cached version of the openapi definition is returned.

Honestly I'm not 100% sure why this is happening. My reading of the Django cache documentation (https://docs.djangoproject.com/en/4.0/topics/cache/ and https://docs.djangoproject.com/en/4.0/ref/settings/#std:setting-CACHES-KEY_FUNCTION) makes it sound like the cache should use the Netbox version as a key, which would make it a different entry in the cache so this shouldn't be a problem.

Hopefully someone with more knowledge about Django caching can reproduce this and figure out why this is happening.

Originally created by @fabi125 on GitHub (Apr 13, 2022). Originally assigned to: @kkthxbye-code on GitHub. ### NetBox version v3.1.11 ### Python version 3.8 ### Steps to Reproduce 1. Install Netbox v3.0.5+ 2. Fetch http://netbox/api/docs/?format=openapi to populate Redis cache 3. Update to another Netbox version. 4. Fetch http://netbox/api/docs/?format=openapi and get the old openapi definition ### Expected Behavior The correct openapi definition should be returned. ### Observed Behavior Stale cached version of the openapi definition is returned. Honestly I'm not 100% sure why this is happening. My reading of the Django cache documentation (https://docs.djangoproject.com/en/4.0/topics/cache/ and https://docs.djangoproject.com/en/4.0/ref/settings/#std:setting-CACHES-KEY_FUNCTION) makes it sound like the cache should use the Netbox version as a key, which would make it a different entry in the cache so this shouldn't be a problem. Hopefully someone with more knowledge about Django caching can reproduce this and figure out why this is happening.
adam added the type: bugstatus: accepted labels 2025-12-29 19:39:43 +01:00
adam closed this issue 2025-12-29 19:39:43 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Apr 28, 2022):

@jeremystretch - Would it make sense to clear the entire cache in the upgrade script? It would require re-adding the command for clearing the cache. netbox-docker would probably also have to be adjusted.

The cache is very sparsely used currently.

@kkthxbye-code commented on GitHub (Apr 28, 2022): @jeremystretch - Would it make sense to clear the entire cache in the upgrade script? It would require re-adding the command for clearing the cache. netbox-docker would probably also have to be adjusted. The cache is very sparsely used currently.
Author
Owner

@jeremystretch commented on GitHub (Apr 28, 2022):

I think that makes sense, yeah. It's probably good practice to clear the cache on upgrade anyway.

Related, I also want to look into pre-rendering the API spec at release time. I'm not sure exactly what that process would look like, but it would avoid the caching issue entirely, and potentially allow us to add the REST API spec to the documentation using mkdocs-plugins. (But that's another discussion.)

@jeremystretch commented on GitHub (Apr 28, 2022): I think that makes sense, yeah. It's probably good practice to clear the cache on upgrade anyway. Related, I also want to look into pre-rendering the API spec at release time. I'm not sure exactly what that process would look like, but it would avoid the caching issue entirely, and potentially allow us to add the REST API spec to the documentation using [mkdocs-plugins](https://github.com/Neoteroi/mkdocs-plugins). (But that's another discussion.)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6350