From 9209f0579fc78af964af4d189fe03e0232d8cf6b Mon Sep 17 00:00:00 2001 From: Alex White Date: Wed, 11 May 2016 14:07:50 -0700 Subject: [PATCH] Fix DataError on login A watched login failure causes a 500 saving a 256 character long username into the login attempts. Conditionally slice it to fit AccessAttempt --- defender/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/defender/utils.py b/defender/utils.py index 2183368..f0d71f3 100644 --- a/defender/utils.py +++ b/defender/utils.py @@ -314,9 +314,13 @@ def add_login_attempt_to_db(request, login_valid): # If we don't want to store in the database, then don't proceed. return + if config.USERNAME_FORM_FIELD in request.POST: + username = request.POST[config.USERNAME_FORM_FIELD][:255] + else: + username = None + user_agent = request.META.get('HTTP_USER_AGENT', '')[:255] ip_address = get_ip(request) - username = request.POST.get(config.USERNAME_FORM_FIELD, None) http_accept = request.META.get('HTTP_ACCEPT', '') path_info = request.META.get('PATH_INFO', '')