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

Add plugin support for apps.get_model() #1725

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

flaeppe
Copy link
Member

@flaeppe flaeppe commented Sep 21, 2023

Attempts to resolve the provided lazy reference to a model type. As such it can now return a specific model depending on what it was called with

Related issues

Closes: #1318
Closes: #304
Closes: #305
Closes: #814

High value comment/discussion: #814 (comment)

Attempts to resolve the provided lazy reference to a model type. As such
it can now return a specific model depending on what it was called with
@flaeppe
Copy link
Member Author

flaeppe commented Sep 21, 2023

Interestingly enough the test that is added doesn't fail locally...

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thanks!

return None

# Reference conforms to the structure of a lazy reference: '<app_label>.<object_name>'
fullname = django_context.model_class_fullnames_by_label_lower.get(reference.lower())
Copy link
Member

Choose a reason for hiding this comment

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

Question about lower: why is that needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

The implementation is case insensitive:

Returns the Model with the given app_label and model_name. As a shortcut, this method also accepts a single argument in the form app_label.model_name. model_name is case-insensitive.

Ref: https://docs.djangoproject.com/en/4.2/ref/applications/#django.apps.apps.get_model

mypy_django_plugin/lib/helpers.py Outdated Show resolved Hide resolved
@flaeppe
Copy link
Member Author

flaeppe commented Sep 21, 2023

Interestingly enough the test that is added doesn't fail locally...

I really can't figure out how to reproduce locally..

@sobolevn would you mind checking out and try it, whenever you'd get a chance?

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

Successfully merging this pull request may close these issues.

Too broad return value for apps.get_model()
2 participants