-
-
Couldn't load subscription status.
- Fork 516
Add django.db.models.fields.related.ForeignObject missing methods and attributes
#2154
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
| @property | ||
| def target_field(self) -> Field: ... | ||
|
|
||
| class ForeignObject(RelatedField[_ST, _GT]): |
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.
Looks like this class has lots of unsolved problems. Let's solve them!
- Please, use
ClassVarwhere needed: https://github.com/django/django/blob/a09082a9bec18f8e3ee8c10d473013ec67ffe93b/django/db/models/fields/related.py#L522-L530
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.
Thank you. As you suggested, I have handled all the relevant parts as class variables.
| django.db.models.fields.related.ForeignObject.path_infos | ||
| django.db.models.fields.related.ForeignObject.related_accessor_class | ||
| django.db.models.fields.related.ForeignObject.requires_unique_target | ||
| django.db.models.fields.related.ForeignObject.get_extra_restriction |
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.
- Let's add other missing attributes to
ForeignObject
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.
I have two questions:
- I tried to define the
get_extra_restrictionmethod, but I encountered an error due to the parameter mismatch with the subclass. I attempted to usetype: ignoreon the method in the subclass, but it was not allowed. What steps can I take to resolve this issue?
error: not checking stubs due to mypy build errors:
django-stubs/contrib/contenttypes/fields.pyi:90: error: Signature of "get_extra_restriction" incompatible with supertype "ForeignObject" [override]
django-stubs/contrib/contenttypes/fields.pyi:90: note: Superclass:
django-stubs/contrib/contenttypes/fields.pyi:90: note: def get_extra_restriction(self, alias: str, related_alias: str) -> None
django-stubs/contrib/contenttypes/fields.pyi:90: note: Subclass:
django-stubs/contrib/contenttypes/fields.pyi:90: note: def get_extra_restriction(self, where_class: Type[WhereNode], alias: Optional[str], remote_alias: str) -> WhereNode
django-stubs/contrib/contenttypes/fields.pyi:92: error: Unused "type: ignore" comment [unused-ignore]- Should I also add the cached_property method?
| error_messages: _ErrorMessagesMapping | None = ..., | ||
| db_comment: str | None = ..., | ||
| ) -> None: ... | ||
| def __copy__(self) -> Empty: ... |
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.
I think this should actually be Self
The Empty class is just an artifact of a weird hack that Django uses, but it modifies the __class__ attribute so that it's no longer actually the Empty class
def __copy__(self):
# We need to avoid hitting __reduce__, so define this
# slightly weird copy construct.
obj = Empty()
obj.__class__ = self.__class__
obj.__dict__ = self.__dict__.copy()
return objThere 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.
Based on your explanation, that seems correct. Thank you for pointing that out!
django.db.models.fields.related.ForeignObjectdjango.db.models.fields.related.ForeignObject missing methods and attributes
I have made things!
Some of the Django 5.0 updates were missing from the related classes, so I added them referring to the allowlist_todo.
If you need any additional work, please let me know and I'll work on it right away. Thank you :)
django.db.models.ForeignObjectdjango.db.models.ForeignObject.__copy__django.db.models.ForeignObject.contribute_to_related_classdjango.db.models.ForeignObject.forward_related_accessor_classdjango.db.models.ForeignObject.get_class_lookupsdjango.db.models.ForeignObject.get_extra_descriptor_filterdjango.db.models.ForeignObject.get_foreign_related_valuedjango.db.models.ForeignObject.get_instance_value_for_fieldsdjango.db.models.ForeignObject.get_joining_columnsdjango.db.models.ForeignObject.get_local_related_valuedjango.db.models.ForeignObject.get_path_infodjango.db.models.ForeignObject.get_reverse_joining_columnsdjango.db.models.ForeignObject.get_reverse_path_infodjango.db.models.ForeignObject.related_accessor_classdjango.db.models.ForeignObject.requires_unique_targetRelated issues
django.db.models.field.related#2151