Opened 10 years ago
Closed 10 years ago
#24210 closed Cleanup/optimization (fixed)
Clean up relational fields __init__ args/kwargs.
Reported by: | Loic Bistuer | Owned by: | Loic Bistuer |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Relational Field
and Rel
have complex constructors with many arguments that are dug out of **kwargs
rather than defined declaratively.
For example:
def __init__(self, to, db_constraint=True, swappable=True, **kwargs): kwargs['verbose_name'] = kwargs.get('verbose_name', None) kwargs['rel'] = ManyToManyRel( self, to, related_name=kwargs.pop('related_name', None), related_query_name=kwargs.pop('related_query_name', None), limit_choices_to=kwargs.pop('limit_choices_to', None), symmetrical=kwargs.pop('symmetrical', to == RECURSIVE_RELATIONSHIP_CONSTANT), through=kwargs.pop('through', None), through_fields=kwargs.pop('through_fields', None), db_constraint=db_constraint, )
This makes it difficult to audit and comprehend and has already resulted in bugs, (e.g. migrations omitting to handle some of the arguments in deconstruct()
).
Change History (3)
comment:1 by , 10 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 10 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:3 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
PR https://github.com/django/django/pull/3971.