Opened 94 minutes ago
Last modified 6 minutes ago
#36921 new Bug
KeyError when adding new objects two relations deep via inlines but the intermediate model is not registered with the admin
| Reported by: | Jacob Walls | Owned by: | |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| Severity: | Release blocker | Keywords: | |
| Cc: | Sean Helvey | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
With these models:
class Analysis(models.Model): ... class Song(models.Model): users = models.ManyToManyField("auth.User") analysis = models.ForeignKey("Analysis", on_delete=models.CASCADE, null=True)
And these admins:
class SongInline(admin.TabularInline): model = Song class AnalysisAdmin(admin.ModelAdmin): inlines = [SongInline] admin.site.register([Analysis], AnalysisAdmin)
- Admin: Analysis: Add
- Click the "+" in the Users column of the Songs inline
- Fill out the field
- Notice
Songis in the URL as thesource_modelarg. This will be a problem, sinceSongis not registered with the admin. - Submit
File "/Users/jacobwalls/django/django/contrib/admin/options.py", line 711, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/utils/decorators.py", line 191, in _view_wrapper result = _process_exception(request, e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/utils/decorators.py", line 189, in _view_wrapper response = view_func(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/views/decorators/cache.py", line 79, in _view_wrapper response = view_func(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/contrib/admin/sites.py", line 247, in inner return view(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/utils/decorators.py", line 47, in _wrapper return bound_method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/views/decorators/debug.py", line 142, in sensitive_post_parameters_wrapper return view(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/utils/decorators.py", line 191, in _view_wrapper result = _process_exception(request, e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/utils/decorators.py", line 189, in _view_wrapper response = view_func(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/contrib/auth/admin.py", line 119, in add_view return self._add_view(request, form_url, extra_context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/contrib/auth/admin.py", line 147, in _add_view return super().add_view(request, form_url, extra_context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/contrib/admin/options.py", line 1984, in add_view return self.changeform_view(request, None, form_url, extra_context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/utils/decorators.py", line 47, in _wrapper return bound_method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/utils/decorators.py", line 191, in _view_wrapper result = _process_exception(request, e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/utils/decorators.py", line 189, in _view_wrapper response = view_func(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/contrib/admin/options.py", line 1842, in changeform_view return self._changeform_view(request, object_id, form_url, extra_context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/contrib/admin/options.py", line 1900, in _changeform_view return self.response_add(request, new_object) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/contrib/auth/admin.py", line 251, in response_add return super().response_add(request, obj, post_url_continue) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jacobwalls/django/django/contrib/admin/options.py", line 1431, in response_add source_admin = self.admin_site._registry[source_model] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exception Type: KeyError at /admin/auth/user/add/ Exception Value: <class 'earTrain.models.Song'>
Regression in b1ffa9a9d78b0c2c5ad6ed5a1d84e380d5cfd010.
Change History (2)
comment:2 by , 7 minutes ago
Replying to Sean Helvey:
How can I help?
If you have reproduced the reported issue, you can accept the ticket saying so. If you also want to work on the ticket, assign it to yourself after accepting. More details on the triage process here: https://docs.djangoproject.com/en/dev/internals/contributing/triaging-tickets/
Thank you!
Note:
See TracTickets
for help on using tickets.
Eek! I'm not familiar with the triage process but believe this patch would add an if statement to check for that. It worked for me locally:
How can I help?