Post request slash append runtime Error

Hi,

I noticed that when making a post request without the trailing slash and having the APPEND_SLASH setting set to True (which is the default value) a runtime error is generated (in CommonMiddleware).

I understand that the exception is generated because the missing trailing slash would require making a redirect, and doing so would cause the loss of the post data.

Many systems (including mine) rely on statistics on status codes to decide instance health and consequent actions (instance replacement / scale out / etc). This behaviour makes it possible to influence the health metrics without a real problem being there, since this could be triggered client-side by making POST requests on the endpoint without the slash.

Wouldn’t it be better to return a client side error (4xx) instead of a server side (5xx) runtime one?

1 Like

Welcome @sipa-echo-zaoa !

Are you currently testing this with DEBUG=True? This should be the only situation in which this occurs, and would be appropriate under those circumstances, since you should never be running with DEBUG=True in a production deployment.

(See the django.middleware.common.CommonMiddleware.get_full_path_with_slash method.)

Hi Ken,

Thanks for the help and the welcome.
Turns out that this behavior is happening only in the development and staging environments where the DEBUG setting is set to True.
So it’s working correctly as expected.