I ran into this issue trying to add simple_history to a model using django-mptt ( https://github.com/django-mptt/django-mptt/ )
The model in question extends MPTTModel, which adds the fields lft
, rght
, tree_id
and level
to the model. However, if I try and save the model, it fails, with the exception:
TypeError: 'rght' is an invalid keyword argument for this function
I did some digging, and when the create_history_model() executes, these fields did not exist. The contents of model._meta.fields at that time was:
[<django.db.models.fields.AutoField: id>, <django.db.models.fields.CharField: name>, <django.db.models.fields.SlugField: url>, <django.db.models.fields.CharField: code>, <mptt.fields.TreeForeignKey: parent>, <django.db.models.fields.TextField: hidden_js>, <django.db.models.fields.related.ForeignKey: faculty>]
However, if I opened up a django shell, and output the contents of the same variable, I got:
[<django.db.models.fields.AutoField: id>, <django.db.models.fields.CharField: name>, <django.db.models.fields.SlugField: url>, <django.db.models.fields.CharField: code>, <mptt.fields.TreeForeignKey: parent>, <django.db.models.fields.TextField: hidden_js>, <django.db.models.fields.related.ForeignKey: faculty>, <django.db.models.fields.PositiveIntegerField: lft>, <django.db.models.fields.PositiveIntegerField: rght>, <django.db.models.fields.PositiveIntegerField: tree_id>, <django.db.models.fields.PositiveIntegerField: level>]
Which does have the additional fields. My conclusion is that the class has not yet been properly initialized at the time class_prepared is fired.