﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22592	AbstractBaseUser.__str__ may return non-string (None)	david.fischer.ch@…	nobody	"Tested under Python 3.

I am writing unit-tests to ensure my custom signal handler works well.
The signal handler is registered to pre_save with sender=AUTH_USER_MODEL and it calls str(instance).

In one of the tests I set user's username to None and save the model, ...

user = User.objects.create(username='sam.fisher', first_name='Sam', last_name='Fisher', password='i_am_the_boss')

user.username = None
user.save()

pre_save signal handler:

    ...
    str(instance)
    ...

Traceback (most recent call last):
  File ""/home/ubuntu/cloudncode_test/server/cloudncode_base/tests/test_models.py"", line 44, in test_strip_none_works
    self.user.save()
  File ""/home/ubuntu/cloudncode_test/venv/src/django/django/db/models/base.py"", line 602, in save
    force_update=force_update, update_fields=update_fields)
  File ""/home/ubuntu/cloudncode_test/venv/src/django/django/db/models/base.py"", line 626, in save_base
    update_fields=update_fields)
  File ""/home/ubuntu/cloudncode_test/venv/src/django/django/dispatch/dispatcher.py"", line 198, in send
    response = receiver(signal=self, sender=sender, **named)
  File ""/home/ubuntu/cloudncode_test/server/cloudncode_base/models/signals.py"", line 55, in strip_strings_and_validate_model
    i = str(instance)
TypeError: __str__ returned non-string (type NoneType)"	Bug	closed	contrib.auth	dev	Normal	invalid			Unreviewed	0	0	0	0	0	0
