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

Does not handle ForeignKey model fields #21

Closed
carlio opened this issue Sep 22, 2014 · 3 comments
Closed

Does not handle ForeignKey model fields #21

carlio opened this issue Sep 22, 2014 · 3 comments

Comments

@carlio
Copy link
Collaborator

carlio commented Sep 22, 2014

A ForeignKey field on a model results in logs of "instance of ForeignKey has no member x" warnings as pylint does not know that Django swaps out the attribute.

carlio added a commit that referenced this issue Sep 24, 2014
… OneToOneField attributes on model classes with an AST node representing the type they "point" to. This will remove all of the "instance of ForeignKey has no attribute X" warnings. In addition, unused import warnings for OneToOneField and ForeignKey have been suppressed, as by replacing the AST node, pylint has no way of knowing that the imports really are used. This is not a perfect solution, as it will suppress genuine unused import warnings, and so may need to be revisited in the future
@carlio carlio closed this as completed Sep 24, 2014
@debuggerpk
Copy link

This fixes only for the first time an attribute is called, not if you have multiple methods e.g.

  @property
  def name(self):
    return self.item.name

  @property
  def category(self):
    return self.item.category.name

  @property
  def family(self):
    return self.item.category.family

  @property
  def outlet_category(self):
    return OutletCategory.objects.get(category=self.item.category, outlet=self.outlet).id

the category, family and outlet_category will raise the error.

@atodorov
Copy link
Contributor

@ysfjwd please open a new issue for your problem and post the entire model class which reproduces the issue and all error logs that you have. What you've given is not enough to reproduce since I have no idea what self.item is!

@debuggerpk
Copy link

@atodorov created a new issue #142

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

No branches or pull requests

3 participants