Skip to content

Repository: Edit Metadata page may not load due to KeyError #4585

Description

@joemull

Describe the bug

There is a chance of a KeyError here:

if self.instance:
self.fields['submission_agreement'].initial = True

Internal Server Error: /elr/repository/manager/3/edit/metadata/
Traceback (most recent call last):
  File "/home/joemull/git/janedb/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/joemull/git/janedb/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/joemull/git/janedb/src/security/decorators.py", line 72, in wrapper
    return func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/joemull/git/janedb/src/security/decorators.py", line 1245, in wrapper
    return func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/joemull/git/janedb/src/repository/views.py", line 1027, in repository_edit_metadata
    metadata_form = forms.PreprintInfo(
                    ^^^^^^^^^^^^^^^^^^^
  File "/home/joemull/git/janedb/src/repository/forms.py", line 63, in __init__
    self.fields['submission_agreement'].initial = True
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'submission_agreement'

Janeway version
1.7.0

Proposed solution
Check for the existence of the field, as it could have been popped off right above.

Metadata

Metadata

Assignees

Labels

Priority highHigh prioritySize XSExtra smallbugSomething's not working

Type

No type

Fields

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