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

MultipleObjectMixin and SingleObjectMixin has incompatible types for queryset and context_object_name #873

Closed
PetrDlouhy opened this issue Mar 15, 2022 · 2 comments

Comments

@PetrDlouhy
Copy link

Bug report

What's wrong

I have view class in django-hordak defined as:

class AccountTransactionsView(LoginRequiredMixin, SingleObjectMixin, ListView):
    ...

Which gives the following mypy errors:

# mypy .
hordak/views/accounts.py:86: error: Definition of "context_object_name" in base class "SingleObjectMixin" is incompatible with definition in base class "MultipleObjectMixin"
hordak/views/accounts.py:86: error: Definition of "queryset" in base class "SingleObjectMixin" is incompatible with definition in base class "MultipleObjectMixin"
Found 2 errors in 1 file (checked 56 source files)

How is that should be

Types for queryset and context_object_name should be made less strict to be compatible similar to solution of issue #152

System information

  • OS: Ubuntu
  • python version: 3.9.7
  • django version: 4.0.2
  • mypy version: 0.931
  • django-stubs version: 1.9.0
  • django-stubs-ext version: 0.3.1
@sterliakov
Copy link
Contributor

sterliakov commented Apr 2, 2022

Probably I misunderstand something, but it looks like unsafe code. SingleObjectMixin.queryset is a queryset to get_object from, it should be QuerySet[Account] (if it is "view listing transactions for account"). MultipleObjectMixin.queryset is queryset you operate on (e.g. render in ListView) - it should be QuerySet[Transaction]. These two bases are really incompatible.

@sterliakov sterliakov mentioned this issue Apr 3, 2022
@intgr intgr removed the bug Something isn't working label Nov 8, 2022
@flaeppe
Copy link
Member

flaeppe commented Jul 31, 2024

As previously mentioned, SingleObjectMixin and ListView classes are, typing wise, incompatible. Currently over the get_context_object_name method

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

No branches or pull requests

4 participants