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

resolve(reverse()) doesn't work when using WSGI / FORCE_SCRIPT_NAME #11716

Open
bferguso opened this issue Jan 7, 2025 · 2 comments · May be fixed by #11717
Open

resolve(reverse()) doesn't work when using WSGI / FORCE_SCRIPT_NAME #11716

bferguso opened this issue Jan 7, 2025 · 2 comments · May be fixed by #11717
Labels

Comments

@bferguso
Copy link
Contributor

bferguso commented Jan 7, 2025

For WSGI applications hosted behind Apache in a sub-path,resolve(reverse(<view name>)) doesn't work. This is currently used in app/search/search_export.py (where the issue was found) and in app/etl_modules/save.py.

The reverse function prepends the URL with the value of settings.FORCE_SCRIPT_NAME, and resolve() can't find it.

For our implementation we have a reverse proxy directing traffic from https://hostname/bc-fossil-management to the Arches WSGI application. We have the FORCE_SCRIPT_NAME set to /bc-fossil-management/. All requests through the reverse proxy function as expected, but when running an export via Celery the search URL can't be found. The cause for this is that reverse("search_results") returns /bc-fossil-management/search/results but the path expected by the URL resolver is /search/results.

Fixed in our instance by change the following:

        func, args, kwargs = resolve(reverse("search_results"))

to

        results_path = reverse("search_results")
        if results_path.startswith(get_script_prefix()):
           results_path = results_path.replace(get_script_prefix(),"/")
        func, args, kwargs = resolve(results_path)

Looks like this was introduced in this commit: a4d11bd

The above seems to work however there may be a cleaner solution.

@bferguso bferguso added the bug label Jan 7, 2025
@chiatt chiatt added this to pipeline Jan 7, 2025
@jacobtylerwalls
Copy link
Member

Good catch @bferguso, following the advice here, your suggestion looks correct to me. Would you like to submit a PR?

@jacobtylerwalls jacobtylerwalls moved this to 🔖 Ready in pipeline Jan 7, 2025
@bferguso
Copy link
Contributor Author

bferguso commented Jan 7, 2025

@jacobtylerwalls - Thanks for having a look. PR is here: #11717
A readme doesn't exist for 7.6.5 (which I'm assuming is the next patch release) so I haven't added a changelog entry. I can add a new empty readme as part of this PR if that's OK.

@jacobtylerwalls jacobtylerwalls moved this from 🔖 Ready to 👀 In Review in pipeline Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 👀 In Review
Development

Successfully merging a pull request may close this issue.

2 participants