Ticket #10808: base.py.diff

File base.py.diff, 1.3 KB (added by jianhuang, 6 years ago)

patch which fixed the diamond inheritance init bug, but with comments

  • base.py

    273273        # Now we're left with the unprocessed fields that *must* come from
    274274        # keywords, or default.
     276        # We're creating a set to keep track of which fields have already
     277        # been assigned values. In the case of diamond inheritance, where
     278        # B and C inherit from A, and D inherits from B and C, D will have
     279        # "redundant" copies of each of A's fields. As we iterate through
     280        # all the fields, the second time we see a field we run the risk of
     281        # reassigning it the default value, so if a field has already been
     282        # seen in set_fields, we ignore it.
     283        set_fields = set()
    276284        for field in fields_iter:
     285            if field.attname in set_fields:
     286                continue
    277287            is_related_object = False
    278288            # This slightly odd construct is so that we can access any
    279289            # data-descriptor object (DeferredAttribute) without triggering its
    311321                setattr(self, field.name, rel_obj)
    312322            else:
    313323                setattr(self, field.attname, val)
     324            set_fields.add(field.attname)
    315326        if kwargs:
    316327            for prop in kwargs.keys():
Back to Top