Closed henrahmagix closed 7 years ago
How were you creating the user/validating it?
Through python manage.py shell_plus
:
User.objects.create()
@KevinEtienne was helping me add a user to a very new system (so I could dumpdata
into a fixture for some e2e tests) and said we could call .create()
with no parameters to see what errors come up, then we'll know what's required. He then remarked that it was odd there were no errors, that in the least email
should not accept blank.
If this is better suited as another mixin instead of changing EmailUserMixin
, or there was a decision to allow blank, then 👍 so I'm just checking if it wasn't a mistake =)
Here's the email
field.. It should be defaulting to blank=False
, but it might be that calling User.objects.create()
pre-fills it with an empty string (since it's a CharField
).
@henrahmagix I imagine that if you run the same command again you'll get an error about how email='' already exists
?
It should be defaulting to
blank=False
, but it might be that callingUser.objects.create()
pre-fills it with an empty string (since it's aCharField
).
If that's the case, then there's no issue? I'm good with that =)
I imagine that if you run the same command again you'll get an error about how
email='' already exists
?
Yarp.
There's sort of technically an issue. In practice, our form fields won't let you submit an empty email address, and a 400 is much friendlier than a 500 (which is what you get from doing it on the model), so it's not a big deal.
I think it's because model validation isn't run by default, except in a ModelForm
. https://docs.djangoproject.com/en/1.10/ref/models/instances/#validating-objects
^ What he said.
(trying to find the right Hot Fuzz gif and failing)
Anyway, s' all good :)
Thanks guys!
https://github.com/incuna/django-user-management/blob/c5cccfa3bc815d1d5923d2a4f96c8ab218f46925/user_management/models/mixins.py#L59-L63
Just encountered an odd thing where I could create a user with no parameters, and there was no error. It doesn't feel right that a blank email isn't validated as false.
@incuna/backend @meshy What do you think?