Skip to content

M2M does not work with multi-model inheritance #1435

@martimarkov

Description

@martimarkov

Describe the bug
M2M does not work if inheriting more than once the base class

To Reproduce
Steps to reproduce the behavior:

class ModelBase(models.Model):
    contact_new = models.ManyToManyField(Contact, verbose_name=_('Contact'), blank=True)


class ApartmentOffer(ModelBase):
    pass

class HouseOffer(ModelBase):
    pass


simple_history.register(ModelBase, cascade_delete_history=True)
simple_history.register(ApartmentOffer, m2m_fields=["contact_new"], cascade_delete_history=True)
simple_history.register(HouseOffer, m2m_fields=["contact_new"], cascade_delete_history=True)

Error:

Cannot assign "<HistoricalApartmentOffer: Apartment Offer - 8988518 as of 2025-01-09 23:00:16.431927+00:00>": "HistoricalPropertyOffer_contact_new.history" must be a "HistoricalPropertyOffer" instance.

Expected behavior
The object should be saved successfully.

Environment (please complete the following information):

  • Django Simple History Version: 3.7.0
  • Django Version: 5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions