-
-
Notifications
You must be signed in to change notification settings - Fork 521
Make Apps.get_model() return Type[Model] #814
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
base: master
Are you sure you want to change the base?
Conversation
|
Hi, @RJPercival! Thanks! This PR is marked as a draft, is there a reason for that? |
|
I wasn't sure whether the fix would be this simple. I've noticed that @yhoiseth tried to fix this back in 2020 but abandoned their PR. There was a suggestion that plugin support would be required. |
sobolevn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, let's be double sure by adding a new unit test for this feature 🤔
Do you agree?
|
I'm not sure of the state of this PR but it seems that only a test case is missing. This is my first go at a test case in this project so I'm not completely sure if this is enough or correct. @RJPercival feel free to include this in your PR or I would be happy to open a PR with your change included. |
According to Django's documentation (https://docs.djangoproject.com/en/4.0/ref/applications/#django.apps.AppConfig.get_model), `get_model()` is guaranteed to return the type of the model (or raise an exception).
|
I’ve rebased the PR and added your test @Majsvaffla . To clarify the past issue discussed in #305 : making Site = django_apps.get_model("sites.Site")
current_site = Site.objects.get_current()The I’m not sure why the tests failed with this change back in #305, and no longer do. I guess the test suite has changed somewhat, perhaps checking Django’s source less strictly? @sobolevn any ideas? Unfortunately #305 is so old we don't have the logs any more. With a from django.contrib.sites.models import Site as RealSite
Site = django_apps.get_model("sites.Site")
assert isinstance(Site, RealSite)
current_site = Site.objects.get_current()…but much of the time, you use Plugin support, as suggested in the original PR, would need us to dynamically switch the return type of Overall I think a more sensible path forward is:
This will be the least disruptive IMO. |
According to Django's documentation,
get_model()is guaranteed to return the type of the model (or raise an exception).Related issues