-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Swagger not updating when new API endpoints added in plugin #18021
Comments
Same problem with v4.1.6 |
Can this be addressed with documentation, e.g. a note that if you add an API endpoint in your plugin you need to flush your redis cache (with accompanying instructions)? |
In my mind what should happen is the cached swagger should clear on container/app startup if its deemed out of date |
here a simple management command that fixes it once called $command_file_name.py
|
This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically. |
@bctiemann what information is missing here? |
Seems like the ideal solution would be for NetBox to invalidate the cache automatically on startup, but what I'm not clear on is what the mechanism should be for it to determine that the Swagger schema is out of date. How should it "know" that anything has changed? Alternatively, the manual cache-clearing script above would do the job, but I wonder if it would be more useful for it to just be a general "clear the entire cache" command, with an optional CLI arg to specify only the matching keys to delete (e.g. |
I'm not a Django power user by any means, but what if instead of caching it in Redis across all instances, it was cached in-memory, per instance, during application startup? This would eliminate the need to bust the cache at all, would keep responses to requests quick and would presumably also clear during app restarts (like when using autoreload in development or when deploying new things). |
@prryplatypus that actually sounds like how it should work -- but looking at the code now it seems like it's already written so as to cache based on a key that depends on the release version (e.g. Lines 57 to 63 in 020386f
I think this handles the general use case of a user upgrading from one published version to another, but it doesn't address the case of a developer adding their own API endpoints within a version. I think developers ought to be able to shoulder clearing the Redis cache manually in this scenario ( I realize (on rereading) that this is already generally known, but it feels like overkill to redesign the whole caching structure just for the sake of developers. (For that same reason I guess the management command approach suggested earlier wouldn't work either, as that would hardly be less work for the developer than just using |
Current proposed solution is to clear the entire Redis cache at startup if (We don't want to flush the cache at startup in production situations because many WSGI/gunicorn workers sharing a Redis would be independently recycling on a regular basis and clearing the cache over and over; but for the purposes of development this should save the effort of clearing the cache with every code change.) |
This seems very reasonable to me, so I'm going to proceed with merging the PR. |
Deployment Type
Self-hosted
Triage priority
N/A
NetBox Version
v4.1.3
Python Version
3.11
Steps to Reproduce
Expected Behavior
swagger should update showing the new endpoint
Observed Behavior
Problem is caused by the caching of the swagger in redis, this needs to be cleared every time in order for the swagger to update. It does appear to load after the cache expires but this takes 24 hours
The text was updated successfully, but these errors were encountered: