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

fix: reset state before evaluating named urls #15683

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions awx/main/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from awx.main.utils.profiling import AWXProfiler
from awx.main.utils.common import memoize
from awx.urls import get_urlpatterns
from awx.main.utils.named_url_graph import reset_counters


logger = logging.getLogger('awx.main.middleware')
Expand Down Expand Up @@ -112,6 +113,7 @@ def _hijack_for_old_jt_name(node, kwargs, named_url):
@classmethod
def _named_url_to_pk(cls, node, resource, named_url):
kwargs = {}
reset_counters()
if node.populate_named_url_query_kwargs(kwargs, named_url):
match = node.model.objects.filter(**kwargs).first()
if match:
Expand Down
11 changes: 11 additions & 0 deletions awx/main/tests/functional/test_named_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,14 @@ def test_named_sub_resource(self, prefix, settings):
URLModificationMiddleware._convert_named_url(f'/api/{prefix}v2/organizations/test_org/inventories/')
== f'/api/{prefix}v2/organizations/{test_org.pk}/inventories/'
)

def test_named_job_template(self):
org = Organization.objects.create(name='test_org')
tpl = JobTemplate.objects.create(name='test_tpl', organization=org)

# first, cause a '404' - we want to verify that no state from previous requests is carried over when named
# urls are resolved
assert URLModificationMiddleware._convert_named_url('/api/v2/job_templates/test/tpl++test_org/') == '/api/v2/job_templates/test/tpl++test_org/'

# try to resolve a valid url - it should succeed
assert URLModificationMiddleware._convert_named_url('/api/v2/job_templates/test_tpl++test_org/') == f'/api/v2/job_templates/{tpl.pk}/'
Loading