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

Make get_or_create func placeholder return (model, bool) tuple #156

Conversation

renatgalimov
Copy link

Otherwise, code like

Model.objects.get_or_create()[0] 

raises pylint error.

@coveralls
Copy link

coveralls commented Apr 15, 2018

Pull Request Test Coverage Report for Build 376

  • 0 of 0 (NaN%) changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 87.7%

Totals Coverage Status
Change from base Build 374: 0.0%
Covered Lines: 549
Relevant Lines: 626

💛 - Coveralls

Copy link
Contributor

@atodorov atodorov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good but is missing tests!

from django.core.exceptions import MultipleObjectsReturned \
as MultipleObjectsReturnedException


def __noop_get_or_create(self, *args, **kwargs):
return (Model(), bool(random.randint(0, 1)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use random ? Why not return just True or False ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is closer to the original one, which may return either True or False and that makes it more error-proof if in the future pylint gets smart enough to run checks based on exact return values of functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I still need a reproducer/test though.

@atodorov
Copy link
Contributor

@femdom can you post the original error being produced ? For some reason I was not able to reproduce. What pylint_django version do you have ?

@daniil-konovalenko
Copy link

daniil-konovalenko commented Jun 5, 2018

@atodorov I've faced the same issue:

managers_group, _ = Group.objects.get_or_create(
    name='Managers',
)

produces

E: Attempting to unpack a non-sequence defined at line 7 of  (unpacking-non-sequence)

I use pylint v1.9.1 and pylint-django v0.11.1

atodorov added a commit that referenced this pull request Aug 2, 2018
the issue is not reproducible after the upgrade to pylint 2.0
where I deleted most of the transformations, including the
offending one.
@atodorov atodorov closed this in 6d151d8 Aug 2, 2018
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

Successfully merging this pull request may close these issues.

4 participants