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

Swagger not updating when new API endpoints added in plugin #18021

Open
tbotnz opened this issue Nov 15, 2024 · 5 comments
Open

Swagger not updating when new API endpoints added in plugin #18021

tbotnz opened this issue Nov 15, 2024 · 5 comments
Labels
complexity: low Requires minimal effort to implement pending closure Requires immediate attention to avoid being closed for inactivity status: revisions needed This issue requires additional information to be actionable type: bug A confirmed report of unexpected behavior in the application

Comments

@tbotnz
Copy link

tbotnz commented Nov 15, 2024

Deployment Type

Self-hosted

Triage priority

N/A

NetBox Version

v4.1.3

Python Version

3.11

Steps to Reproduce

  1. add an endpoint to an API plugin
  2. reload netbox

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

@tbotnz tbotnz added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Nov 15, 2024
@Bacloud
Copy link

Bacloud commented Nov 15, 2024

Same problem with v4.1.6

Copy link
Contributor

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)?

@bctiemann bctiemann removed the status: needs triage This issue is awaiting triage by a maintainer label Nov 15, 2024
@bctiemann bctiemann added status: revisions needed This issue requires additional information to be actionable complexity: low Requires minimal effort to implement labels Nov 15, 2024 — with Linear
@tbotnz
Copy link
Author

tbotnz commented Nov 15, 2024

In my mind what should happen is the cached swagger should clear on container/app startup if its deemed out of date

@tbotnz
Copy link
Author

tbotnz commented Nov 15, 2024

here a simple management command that fixes it once called python manage.py $command_file_name

$command_file_name.py

from django.core.management.commands.makemigrations import Command as _Command

from django.core.cache import cache


class Command(_Command):

    def handle(self, *args, **kwargs):
        """ Temporary command to clear cache keys that are not cleared by the cache clear command. """
        _KEYS_PREFIX_REQUIRING_CLEARING = [
            "*api_schema_*",
        ]
        for key_prefix in _KEYS_PREFIX_REQUIRING_CLEARING:
            matched_keys_to_delete = cache.keys(key_prefix)
            for matched_key in matched_keys_to_delete:
                cache.delete(matched_key)

Copy link
Contributor

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.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: low Requires minimal effort to implement pending closure Requires immediate attention to avoid being closed for inactivity status: revisions needed This issue requires additional information to be actionable type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants