New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ANONYMOUS_USER_NAME None value #409
Comments
Yes, you are right, that does look dodgy. Need a way to be able to default to 'AnonymousUser' without preventing it being explicitly set to None. |
What if I changed the code to the following? Any better? This should set the default value if nothing specified and allow explicitly setting it to None. try:
ANONYMOUS_USER_NAME = settings.ANONYMOUS_USER_NAME
except AttributeError:
try:
ANONYMOUS_USER_NAME = settings.ANONYMOUS_DEFAULT_USERNAME_VALUE
warnings.warn("The ANONYMOUS_DEFAULT_USERNAME_VALUE setting has been renamed to ANONYMOUS_USER_NAME.", DeprecationWarning)
except AttributeError:
ANONYMOUS_USER_NAME = "AnonymousUser" |
I'd say just remove the two line I commented. Since So I would stick to: ANONYMOUS_USER_NAME = getattr(settings, 'ANONYMOUS_USER_NAME', None)
if ANONYMOUS_USER_NAME is None:
ANONYMOUS_USER_NAME = getattr(settings, 'ANONYMOUS_DEFAULT_USERNAME_VALUE', None)
if ANONYMOUS_USER_NAME is not None:
warnings.warn("[...]", DeprecationWarning) and remove the aformentioned two lines. I have mixed feelings about the |
If we don't provide a default value for ANONYMOUS_USER_NAME, this is going to break existing applications that assume a default value is going to be provided. i.e. we have changed the behaviour for when the ANONYMOUS_USER_NAME setting is not given. |
Then why not bumping to 1.5.0, removing |
I believe the intention was to allow running Django Guardian without it automatically creating an anonymous user. Do you have a use case for this? Why not just ignore the anonymous user if you don't want it? I think creating an anonymous user by default is a good thing, I don't see any reason why we should change this. However we do need a default value of The |
What I meant was it's not because everyone does one thing that it's the right/better way. Forcing the creation of an Anonymous User could be a way to go, but then the docs should be updated. Regarding my situation, I'm using an email field as the default USERNAME_FIELD, hence my initial reluctance to create the anonymous user instance. But I can manage. Cheers. And thanks for letting me bust your b*lls. |
Guys, I don't really think that requiring the creation of an anonymous user is a good idea. I've been using |
So my solution involving |
@brianmay Sorry about the confusion. 👍 for the fix, though! |
Am I missing something or with this line in
guardian.conf.settings
ANONYMOUS_USER_NAME cannot ever be equal to None, thus voiding the fact that it is supposed to optional. Looks to me that this was not desired.
Cheers
The text was updated successfully, but these errors were encountered: