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

Fix ForeignKey queryset filters for cases where the to argument is a … #1436

Merged
merged 2 commits into from Apr 14, 2023

Conversation

Kircheneer
Copy link
Contributor

…string like 'app_label.model_name'.

I have made things!

Related issues

Refs #626 (probably closes, but my use case is only similar, not exactly the same.

This fixes lookups for related_cls where it was assumed the to field on a foreign key would always be a class. If it is a string however (using app_label.model_name notation), this breaks some things.

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, but this would need a test case.

@Kircheneer
Copy link
Contributor Author

Kircheneer commented Apr 13, 2023

Thanks, but this would need a test case.

Sure! Apparently it has also broken a bunch of things, I will take a look into that.

@Kircheneer
Copy link
Contributor Author

I have switched approaches here a little because I discovered this only applies when abstract base classes are involved. From the docs:

Relationships defined this way on abstract models are resolved when the model is subclassed as a concrete model and are not relative to the abstract model’s app_label:

I have changed the logic to accommodate for this and added a test.

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.

Thank you! Just one nit left :)

mypy_django_plugin/django/context.py Show resolved Hide resolved
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.

🎉

@sobolevn sobolevn merged commit 4bd89cd into typeddjango:master Apr 14, 2023
15 checks passed
@Kircheneer Kircheneer deleted the fix-foreign-key branch April 14, 2023 08:19
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.

None yet

2 participants