Model instances without primary key value are unhashable in admin panel
See original GitHub issueI have implemented a “backup” functionality when a user wants to keep a revision of his object along with all the related ones. I have implemented the admin integration and registered all the “follows” correctly. When the user presses the “create new backup” button, then the following code is executed:
with reversion.create_revision():
main_object.save()
reversion.set_user(request.user)
reversion.set_comment(comment)
and a revision is created for the object and all the related ones.
The problem appears when I create a new object that has a relationship to the main_object
. When the new object is created, if the user presses “Create new Backup”, then a revision is successfully created for the main_object and all the related ones BUT the previous revisions show this message on the admin panel: "Model instances without primary key value are unhashable".
The traceback that appears is:
File "/Users/platico/PycharmProjects/news-service/src/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/platico/PycharmProjects/news-service/src/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
110. response = view_func(request, *args, **kwargs)
File "/Users/platico/PycharmProjects/news-service/src/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/Users/platico/PycharmProjects/news-service/src/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
233. return view(request, *args, **kwargs)
File "/Users/platico/PycharmProjects/news-service/src/lib/python2.7/site-packages/reversion/admin.py" in revision_view
238. context,
File "/Users/platico/PycharmProjects/news-service/src/lib/python2.7/site-packages/reversion/admin.py" in _reversion_revisionform_view
184. version.revision.revert(delete=True)
File "/Users/platico/PycharmProjects/news-service/src/lib/python2.7/site-packages/reversion/models.py" in revert
89. if item not in old_revision:
File "/Users/platico/PycharmProjects/news-service/src/lib/python2.7/site-packages/django/db/models/base.py" in __hash__
521. raise TypeError("Model instances without primary key value are unhashable")
with an Exception Type of TypeError and an Exception Value of Model instances without primary key value are unhashable
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (8 by maintainers)
Top GitHub Comments
Cool, I’ll aim for a release sometime next week! Thanks for your help!
On 20 November 2017 at 09:13, Roman Karpovich notifications@github.com wrote:
Same problem for me. Multi-table inheritance.