brack3t/django-braces

Fail hard when user is not passed in UserKwargModelFormMixin

driesdesmet opened this issue · 2 comments

Maybe I'm thinking about this only with my usecase, but what was the reasoning behind falling back to None if the user isn't provided in the UserKwargModelFormMixin? If you were to depend the functionality of a form on a user, wouldn't it make sense to make the user argument mandatory? Either fail with a KeyError or fall back on AnonymousUser makes more sense I think. The second solution would at least make sure the self.user is an actual User objects instead of None.

We can't make those assumptions for you, though. Defaulting the user to None allows you to catch if the user is there or not and do with it what you want/need.

Yep, my thinking was to fail as early as possible, but I see now that you'd want to make use of this form mixin even if a user is not always in the keyword arguments. I thank you kindly for the work / consideration. I use this mixin in nearly all django projects.