Hello, I have an Event model (for an event like a concert or a play) that can have many Event_Dates (different showing dates and times of the concert of play). The model relation is implemented with a ForeignKey from the Event_Date model to the Event.
In the django admins, I have the Event_Dates included as an inline in the Event admin page. The inline code: class EventDateInline( admin.StackedInline ): model = Event_Date extra = 2 fk_name = 'event' fieldsets = [ ( None, { 'fields' : [ 'start_date', 'start_time', 'end_time' ] } ), ( "Optional End Date and Description", { 'fields' : [ 'end_date', 'description' ], 'classes' : ( "collapse", ) } ), ] #-- END EventDateInline StackedInline class --# And the code where the inline is included in the Event: inlines = [ #EventPresenterInline, EventDateInline, EventImageInline, ] Pretty standard stuff based on what I know of django. When the users of this application need to make a new Event that is an annual update of an event that is put on once each year (the Nutcracker, for instance - multiple performances every December), they go to last year's Event in the admin, check the "delete" checkbox next to all but one of the dates, then use the "Save as new" button to make a new Event. This worked fine in django versions 1.2 through 1.6. A new event was created with one new date. In 1.7, when one does this, one gets the following error: TypeError at /path/to/event/edit/ Model instances without primary key value are unhashable Request Method: POST Request URL: http://example.com/path/to/event/edit/ Django Version: 1.7.1 Exception Type: TypeError Exception Value: Model instances without primary key value are unhashable Exception Location: /path/to/virtualenv/lib/python2.7/site-packages/django/db/models/base.py in __hash__, line 485 Python Executable: /usr/bin/python Python Version: 2.7.8 In looking online, the one post I found that might be related is: http://stackoverflow.com/questions/26081146/django-1-7-passing-around-unsaved-instances-throws-unhashable-exception But in my case, while there is a signal associated with Event (on save, it looks up related Event Presenters, creates a string list of their names, then places that string in a field in the Event), it isn't anywhere in the stack trace for the error (below). Initially, if anyone could help me figure out if this is a behavior that has changed in django versus one that might be related to my code, I'd appreciate it. I tried disabling all the signals in my application (there are 4 - I removed them from my code-base entirely, then rebooted the server to make sure apache and wsgi were looking at the current code) and the problem persisted. I honestly was surprised that it used to work, am trying to figure out what to tell the user. For now, "Save as new" where one does not remove any Event_Dates works, so I advised the user to just do that, then update dates as needed in the new record. Any help will be greatly appreciated. Thanks, Jon ====================================== stack trace: ====================================== Traceback: File "/path/to/virtualenv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 111. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper 584. return self.admin_site.admin_view(view)(*args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 105. response = view_func(request, *args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 52. response = view_func(request, *args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner 204. return view(request, *args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view 1457. return self.changeform_view(request, object_id, form_url, extra_context) File "/path/to/virtualenv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 29. return bound_func(*args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 105. response = view_func(request, *args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 25. return func.__get__(self, type(self))(*args2, **kwargs2) File "/path/to/virtualenv/lib/python2.7/site-packages/django/db/transaction.py" in inner 394. return func(*args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view 1392. current_app=self.admin_site.name)) File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view 1454. return self.changeform_view(request, None, form_url, extra_context) File "/path/to/virtualenv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 29. return bound_func(*args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 105. response = view_func(request, *args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 25. return func.__get__(self, type(self))(*args2, **kwargs2) File "/path/to/virtualenv/lib/python2.7/site-packages/django/db/transaction.py" in inner 394. return func(*args, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view 1404. if all_valid(formsets) and form_validated: File "/path/to/virtualenv/lib/python2.7/site-packages/django/forms/formsets.py" in all_valid 438. if not formset.is_valid(): File "/path/to/virtualenv/lib/python2.7/site-packages/django/forms/formsets.py" in is_valid 303. self.errors File "/path/to/virtualenv/lib/python2.7/site-packages/django/forms/formsets.py" in errors 277. self.full_clean() File "/path/to/virtualenv/lib/python2.7/site-packages/django/forms/formsets.py" in full_clean 343. self.clean() File "/path/to/virtualenv/lib/python2.7/site-packages/django/forms/models.py" in clean 641. self.validate_unique() File "/path/to/virtualenv/lib/python2.7/site-packages/django/forms/models.py" in validate_unique 648. valid_forms = [form for form in self.forms if form.is_valid() and form not in forms_to_delete] File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/options.py" in is_valid 1853. self.hand_clean_DELETE() File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/options.py" in hand_clean_DELETE 1833. collector.collect([self.instance]) File "/path/to/virtualenv/lib/python2.7/site-packages/django/contrib/admin/utils.py" in collect 180. return super(NestedObjects, self).collect(objs, source_attr=source_attr, **kwargs) File "/path/to/virtualenv/lib/python2.7/site-packages/django/db/models/deletion.py" in collect 168. reverse_dependency=reverse_dependency) File "/path/to/virtualenv/lib/python2.7/site-packages/django/db/models/deletion.py" in add 85. if obj not in instances: File "/path/to/virtualenv/lib/python2.7/site-packages/django/db/models/base.py" in __hash__ 485. raise TypeError("Model instances without primary key value are unhashable") Exception Type: TypeError at /path/to/event/edit/ Exception Value: Model instances without primary key value are unhashable -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/086ea866-6cc3-4747-b399-72b1340f3f5b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.