question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model.object and djangos @classproperties not working since 1.13.1

See original GitHub issue

Bug report

Hello 😃 first of all thank you very much for releasing the new version 1.13.1 so quickly after I asked for it! But now I am facing two new problems, which might be related so I’m posting them together.

Steps to reproduce

See my separately crafted repo with minimal steps to reproduce: https://github.com/djbrown/mypy-django-bugs

But basically it’s:

  • pip install django mypy django-stubs==1.13.0
  • generate simple django project and include above bug snippets
  • execute mypy check -> ✔
  • pip install django-stubs==1.13.1
  • execute mypy check -> ❌
  • pip install django-stubs==1.13.0
  • execute mypy check -> ✔

So it’s definitely the new version… I can also add a failing test or workflow so you don’t have to reproduce manually.

[Collapsed: This part of the report was resolved]

no attribute Model.objects

from django.db.models import Model
def invalid(model: Model):
    model.objects

Results in error: "Model" has no attribute "objects" [attr-defined] I already tried to fix by enabling monkey-patching in settings.py or module via django_stubs_ext or use ModelBase or TypeVar instead of Model. Because in https://github.com/typeddjango/django-stubs/pull/1150 the object property was moved from Model to ModelBase - but that doesn’t work for me.

Maybe also related issues:

cannot access classproperties

from django.test import LiveServerTestCase
class ServerTestCase(LiveServerTestCase):
    def invalid(self, arg: str):
        self.live_server_url

Results in:

error: Argument 1 to "__get__" of "classproperty" has incompatible type "ServerTestCase"; expected "Optional[classproperty[Any]]"  [arg-type]
error: Argument 2 to "__get__" of "classproperty" has incompatible type "Type[ServerTestCase]"; expected "Type[classproperty[Any]]"  [arg-type]

I already tried to fix by enabling monkey-patching in settings.py or module via django_stubs_ext, or access classproperty via class or super class. Accessing normal class attributes works fine though.

System information

  • OS: ubuntu
  • python version: 3.10.4
  • django version: 4.1.4
  • mypy version: 0.991
  • django-stubs version: 1.13.1
  • django-stubs-ext version: 0.7.0

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
djbrowncommented, Dec 8, 2022

thanks 😃 I reviewed your PR and applied the patch locally. that fixes the problem too - and more correctly 😃

1reaction
dlesbrecommented, Dec 8, 2022

@dlesbre Please open a separate issue, tracking multiple different problems in one issue gets messy.

Done #1286

Read more comments on GitHub >

github_iconTop Results From Across the Web

New problem when typing custom Model.objects in version ...
After updating to version 1.13.1 I've add a new typing problem appear in my ... Model.object and djangos @classproperties not working since 1.13.1...
Read more >
Django model property is not working - Stack Overflow
Show activity on this post. I'm facing a issue with while trying to define a property in Django model and access them. I...
Read more >
Open Source Used In Firepower 7.0.0 - Cisco
This document contains licenses and notices for open source software used in this product. With respect to the free/open source software listed in...
Read more >
sphinx-all command man page - python3-sphinx | ManKier
After installation, type sphinx-build --version on the command prompt. If everything worked fine, you will see the version number for the Sphinx package...
Read more >
Search Results - CVE
The mission of the CVE® Program is to identify, define, and catalog publicly disclosed cybersecurity vulnerabilities.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found