Skip to content

Creating historical records for models with M2M fields to "self" causes FieldError #1126

Closed
@ddabble

Description

@ddabble

Describe the bug
See title.

To Reproduce
Steps to reproduce the behavior:

  1. Given the following model:
    class Person(models.Model):
        relations = models.ManyToManyField("self")
        history = HistoricalRecords(m2m_fields=[relations])
  2. Run the following code (which should also create a historical record for the Person object):
    Person.objects.create()
  3. This will produce the following error:
    django.core.exceptions.FieldError: Cannot resolve keyword 'person' into field. Choices are: from_person, from_person_id, id, to_person, to_person_id
    

Expected behavior
That a model object and associated historical record were successfully created, and that the error was not raised.

Environment (please complete the following information):

  • OS: Windows 11 22H2
  • Django Simple History Version: the current master branch
  • Django Version: 4.1.6
  • Database Version: SQLite 3.38.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues related to confirmed bugs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions