Skip to content

KeyError: 'changed_data' in nested_admin.formsets.save_existing_objects #245

@scottgigante

Description

@scottgigante

nested_admin.formsets.save_existing_objects seems to be accessing a field that sometimes does not exist. I'm not quite sure how to generate a MRE here, but this is the traceback from my app logs.

Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/django/forms/models.py", line 1538, in to_python
value = self.queryset.get(**{key: value})
File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get
raise self.model.DoesNotExist(
MyModel.DoesNotExist: MyModel matching query does not exist.

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/nested_admin/formsets.py", line 304, in save_existing_objects
pk_value = form.fields[pk_name].clean(raw_pk_value)
File "/usr/local/lib/python3.11/site-packages/django/forms/fields.py", line 198, in clean
value = self.to_python(value)
File "/usr/local/lib/python3.11/site-packages/django/forms/models.py", line 1540, in to_python
raise ValidationError(
django.core.exceptions.ValidationError: ['Select a valid choice. That choice is not one of the available choices.']

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/django/utils/decorators.py", line 46, in _wrapper
return bound_method(*args, **kwargs)
File "/usr/local/lib/python3.11/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1747, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/usr/local/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1799, in _changeform_view
self.save_related(request, form, formsets, not add)
File "/usr/local/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1255, in save_related
self.save_formset(request, form, formset, change=change)
File "/usr/local/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1243, in save_formset
formset.save()
File "/usr/local/lib/python3.11/site-packages/nested_admin/formsets.py", line 154, in save
instance = self.get_saved_instance_for_form(form, commit, form_instances)
File "/usr/local/lib/python3.11/site-packages/nested_admin/formsets.py", line 237, in get_saved_instance_for_form
instances = self.save_existing_objects([form], commit)
File "/usr/local/lib/python3.11/site-packages/nested_admin/formsets.py", line 314, in save_existing_objects
form.__dict__["changed_data"].append(pk_name)
KeyError: 'changed_data'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions