Opened 7 hours ago

Last modified 5 hours 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 Version 1

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 (last modified by elonzh)

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.


I'd like to create a patch if this ticket is confirmed.

Change History (1)

in reply to:  description comment:1 by elonzh, 7 hours ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top