Opened 9 years ago

Closed 9 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


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),

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 Loic Bistuer, 9 years ago

Has patch: set
Owner: changed from nobody to Loic Bistuer
Status: newassigned

comment:2 by Tim Graham, 9 years ago

Triage Stage: UnreviewedReady for checkin

comment:3 by Loic Bistuer <loic.bistuer@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 84b6c768301096849f5589d7612b129c5445abd3:

Fixed #24210 -- Cleaned up relational fields init().

Thanks Collin Anderson and Tim Graham for the reviews.

Note: See TracTickets for help on using tickets.
Back to Top