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

Do many related manager creation during semantic analysis #2231

Merged
merged 2 commits into from
Jun 23, 2024

Conversation

flaeppe
Copy link
Member

@flaeppe flaeppe commented Jun 22, 2024

When finding a ManyToManyField we can directly create 2 ManyRelatedManagers, one for each side of the relation. This makes the model declaring the ManyToManyField be the one who contributes the ManyRelatedManagers.

Trying to place some related code closer to each other. This time we move some code out of the type checking phase to semantic analysis.

Refs:

flaeppe added 2 commits June 22, 2024 21:29
When finding a `ManyToManyField` we can directly create 2
`ManyRelatedManager`s, one for each side of the relation.
Comment on lines +30 to +36
# '<Model>_ManyRelatedManager' entries are plugin generated and these subclasses only exist
# _locally/dynamically_ runtime -- Created via
# 'django.db.models.fields.related_descriptors.create_forward_many_to_many_manager'
django.contrib.auth.models.Group_ManyRelatedManager
django.contrib.auth.models.Permission_ManyRelatedManager
django.contrib.auth.models.User_ManyRelatedManager

Copy link
Member Author

Choose a reason for hiding this comment

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

These are only here since the stubs includes = ManyToManyField(...) in the following places:

class Group(models.Model):
objects: ClassVar[GroupManager]
name = models.CharField(max_length=150)
permissions = models.ManyToManyField(Permission)

class PermissionsMixin(models.Model):
is_superuser = models.BooleanField()
groups = models.ManyToManyField(Group)
user_permissions = models.ManyToManyField(Permission)

Once they would move to a type hint form like: field: ManyToManyField[..., ...] they will disappear from the allowlist.

@flaeppe flaeppe merged commit edfebe4 into typeddjango:master Jun 23, 2024
36 checks passed
@flaeppe flaeppe deleted the fix/move-related-manager-creation branch June 23, 2024 06:57
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.

2 participants