Skip to content
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

Parameters differ from overridden 'save' method #94

Closed
rgaiacs opened this issue Apr 26, 2017 · 9 comments
Closed

Parameters differ from overridden 'save' method #94

rgaiacs opened this issue Apr 26, 2017 · 9 comments
Labels

Comments

@rgaiacs
Copy link

rgaiacs commented Apr 26, 2017

I have

class Claimant(models.Model):

    ...

    def save(self, *args, **kwargs):
        ...

        super(Claimant, self).save(*args, **kwargs)

and I'm getting

$ grep django pylintrc 
load-plugins=pylint_django
$ python -m pylint --version
__main__.py 1.7.1, 
astroid 1.5.2
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
$ python -m pylint lowfat   
************* Module lowfat.models
W:279, 4: Parameters differ from overridden 'save' method (arguments-differ)

------------------------------------------------------------------
Your code has been rated at 9.98/10 (previous run: 9.98/10, +0.00)

Line 279 is

    def save(self, *args, **kwargs):

Am I doing something wrong?

@yashLadha
Copy link

Try to use

def save(self, force_insert=False, force_update=False, using=None,
             update_fields=None): 

@alexkahn
Copy link

That's a decent work around but for this specific case, the django docs show us a way (not necessarily the way) to override a save method. In the case of this plugin, I would like to be able to either mark the line as not wanting that particular rule applied or have it issue a warning that I should make an explicit setting to ignore that rule in the case of save and delete on implementations of models.Model.

Frost added a commit to Karspexet/Karspexet that referenced this issue Nov 22, 2017
This is in fact not an error, but rather the exact way Django suggests that one
overrides the `save()` method on a model.

See
https://docs.djangoproject.com/en/1.11/topics/db/models/#overriding-predefined-model-methods
for more info on that, and
pylint-dev/pylint-django#94 for info on this error.
@atodorov
Copy link
Contributor

You should be able to disable this warning by adding # pylint: disable=W:279 as done in the commit by @Frost. The actual definition of save() in Django is as shown by @yashLadha.

As to why Django documents the preferred way of overriding using *args and **kwargs I can only speculate that it is because of future compatibility. However this seems wrong to me. At the very least how is one supposed to know what parameters does such an overriden method take?

IMO pylint_django is doing what it is supposed to do. If you'd like it different simply disable the warning. Closing as wontfix.

@jsmedmar
Copy link

jsmedmar commented Apr 8, 2018

I think **kwargs only should not raise the warning. Isn't that the purpose of ** anyways?

@ivancarrancho
Copy link

ivancarrancho commented Sep 14, 2018

If is django version more than 2*
and the issue is in the listview,
should be: def functionName(self, *, object_list=None, **kwargs):

@lokesh1729
Copy link

adding # pylint: disable=W0221 is working...

5pence added a commit to uktrade/lite-api that referenced this issue Jul 18, 2019
5pence added a commit to uktrade/lite-api that referenced this issue Jul 18, 2019
@schumannd
Copy link

schumannd commented Dec 6, 2019

I don't think this fixes the issue, does it? The rule itself is useful, so disabling it for the whole project is not a good solution IMO

Edit: just read that its closed as wont fix. Is there an option to only disable certain rules for a certain line of code?

@jonathan-golorry
Copy link

This is an open issue in pylint, not specific to pylint-django: pylint-dev/pylint#1482

@schumannd Commenting # pylint: disable=W0221 or # pylint: disable=arguments-differ should disable the check only for the commented line.

djjudas21 pushed a commit to camerahub/camerahub that referenced this issue Apr 28, 2020
dyakhnov added a commit to mytardis/mytardis that referenced this issue May 4, 2020
dyakhnov added a commit to mytardis/mytardis that referenced this issue May 4, 2020
dyakhnov added a commit to mytardis/mytardis that referenced this issue May 4, 2020
dyakhnov added a commit to mytardis/mytardis that referenced this issue May 4, 2020
@gitaarik
Copy link

gitaarik commented May 4, 2020

I find the error message useful when you don't use *args, **kwargs, but when I do use it, I use it because I don't want to bother about the arguments, and yes, for backwards compatibility.

It would be nice if you could set an option so that the error won't show up when using *args, **kwargs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants