-
Notifications
You must be signed in to change notification settings - Fork 41
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
Warning running makemigrations
after updating to Django 3.1 and django-currentuser 0.5.1
#43
Comments
Thank you for the detailed bug report. I assume Django 3.1 passes a new built-in kwarg which CurrentUser should expect but does not. Though we will need to look into the docs/source for that since we don't use 3.1 yet. |
I have the same warning (I guess):
I'm using this setup:
|
Same issue here! It seems like this issues is specific to when using a custom user model. Did some digging into this by adding print statements here and found that the kwargs: {..., "to": "accounts.user"}
self.defaults: {..., "to": "accounts.User"} Updating AUTH_USER_MODEL = "accounts.user" Now the bigger question is which of the following is correct:
Any thoughts on what is the right approach to fix this issue? |
I cannot say anything about this solution because I'm using a custom model for user |
@avinashjoshi and @N1K1TAS95 are you using version 0.5.2 of this library? I submitted a fix and had it merged, I believe this issue should be closed unless it still appears to happen on the latest version. See: https://github.com/PaesslerAG/django-currentuser/releases/tag/0.5.2 |
I tried to reinstall the package (last version 0.5.2), but I still have the same warning. Maybe it's my fault? Currently I'm using the CurrentUserFiled as this:
Maybe I'm missing some args or kwargs? |
I can confirm that this is happening using |
@fgs-dbudwin any updates on this? |
Changing |
I mean, it's a solution, but I don't like this given that django recommends the |
Same problem here, any idea when it could be solved? |
I am also hitting this issue, but I am not using any custom user model. I'm using |
As a test I updated the def _warn_for_shadowing_args(self, *args, **kwargs):
if args:
warnings.warn(self.warning)
else:
for key in set(kwargs).intersection(set(self.defaults.keys())):
if not kwargs[key] == self.defaults[key]:
warnings.warn(
self.warning + f" Unexpected arg was: {key}={repr(kwargs[key])}."
f" Default is: {repr(self.defaults[key])}"
)
break This results in:
or
I wonder whether it would be nice to include this as an update so it's more obvious which unexpected args were passed. Running a Django shell I can see that my user model is set to Here's an option for handling the simple difference in case, in the def __init__(self, *args, **kwargs):
self.on_update = kwargs.pop("on_update", False)
# If `to` is present in kwargs, and the same when ignoring case then
# update `to` to use the defaults.
# Fix for https://github.com/PaesslerAG/django-currentuser/issues/43
if "to" in kwargs and kwargs["to"].lower() == self.defaults['to'].lower():
kwargs["to"] = self.defaults['to']
self._warn_for_shadowing_args(*args, **kwargs)
... It does feel a little hacky, but it should be safe, and prevent the warning for users that are using the default user model. |
Fix issue where a warning is raised when running makemigrations when user model is passed with different case to the default. This commonly happens when the default is `auth.User` and `auth.user` is passed in the `to` field. The fix is to detect the case difference, and update the incoming args to match the default. Relates to zsoldosp#43.
Fix issue where a warning is raised when running makemigrations when user model is passed with different case to the default. This commonly happens when the default is `auth.User` and `auth.user` is passed in the `to` field. The fix is to detect the case difference, and update the incoming args to match the default. Relates to zsoldosp#43.
Environment:
Problem:
When I run
python manage.py makemigrations
I get the following warning. This warning is new after updating to the latest version of Django and django-currentuser. If I revert Django to3.0.X
the warning will go away.I have one reference to
CurrentUserField
in my project:I use
UserTrackingModel
as a base class for some of my models, like so:Desired Outcome
I would like to be able to generate migrations without getting a warning that could potentially turn into a bigger problem down the road.
The text was updated successfully, but these errors were encountered: