Opened 4 weeks ago
Last modified 4 weeks ago
#35851 closed New feature
django.test.client.ClientMixin._login doest not set enviorn like REMOTE_ADDR can cause test failures in certain situations — at Initial Version
Reported by: | elonzh | Owned by: | |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | elonzh | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Our service listens for the user_logged_in signal to log the user's IP information, but when using TestClient.login/force_login, the absence of REMOTE_ADDR results in an error.
By reviewing the source code, I found that TestClient.login/force_login(https://github.com/django/django/blob/main/django/test/client.py#L869-L882) creates an empty HttpRequest, which behaves differently from django.test.client.Client.request(https://github.com/django/django/blob/main/django/test/client.py#L401-L436).
Therefore, I believe this is an issue that needs to be addressed.