whitenoise icon indicating copy to clipboard operation
whitenoise copied to clipboard

Revert change to use get_script_prefix

Open sarahboyce opened this issue 1 year ago • 4 comments

Hello :wave:

This reverts this change https://github.com/evansd/whitenoise/pull/259 which added the use of get_script_prefix in the middleware init. Unfortunately this function is not designed to be used outside the request response cycle and as middleware is initialised outside of that, this is causing unexpected results. For now reverting this change is the best solution to resolve this issue https://github.com/evansd/whitenoise/issues/271 :+1:

Note: You can see here a suggestion to have a better way to access this outside the request response cycle is being discussed

sarahboyce avatar Apr 04 '23 17:04 sarahboyce

@evansd @adamchainz I've now added a changelog, I think this is ready for a review :+1:

sarahboyce avatar Apr 06 '23 06:04 sarahboyce

@sarahboyce Can you give some clarification on what "unexpected results" you are seeing with the current implementation?

Archmonger avatar Aug 27 '24 09:08 Archmonger

@sarahboyce Can you give some clarification on what "unexpected results" you are seeing with the current implementation?

This should be mostly captured by this ticket to Django: https://code.djangoproject.com/ticket/34028 get_script_prefix is designed to be only used in the request response cycle. Here is is being used in the Middleware init (so during setup) and as a result settings such as FORCE_SCRIPT_NAME are not respected

sarahboyce avatar Aug 30 '24 08:08 sarahboyce

Thanks for the clarification. Working on getting it merged within ServeStatic, a fork of WhiteNoise for continued maintenance and feature updates.

To leave some breadcrumbs just incase the WhiteNoise maintainers one day revisit the PR backlog:

  • The tests in this PR needed some love.
  • This PR needs some documentation updates to SERVESTATIC_STATIC_PREFIX
  • Everything else is otherwise looking good.

Archmonger avatar Aug 30 '24 08:08 Archmonger