Repository: pretix/pretix

Issue:
Internal Server Error: KeyError: 'payment_stripe_secret_key'
when entering "*****" as secret key into the stripe payment plugin I get this internal server error:

```
ERROR 2022-01-29 19:52:01,164 django.request log Internal Server Error: /control/event/test/test/settings/payment/stripe_settings
Traceback (most recent call last):
  File "/var/pretix/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/var/pretix/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/var/pretix/venv/lib/python3.8/site-packages/pretix/control/permissions.py", line 69, in wrapper
    return function(request, *args, **kw)
  File "/var/pretix/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/var/pretix/venv/lib/python3.8/site-packages/pretix/control/views/event.py", line 431, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/var/pretix/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/usr/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/var/pretix/venv/lib/python3.8/site-packages/pretix/control/views/event.py", line 453, in post
    self.form.save()
  File "/var/pretix/venv/lib/python3.8/site-packages/pretix/base/forms/__init__.py", line 118, in save
    self.cleaned_data[k] = self.initial[k]
KeyError: 'payment_stripe_secret_key'
```


Discussion:
In this case, "*****" literally means "five asterisks", or did you put in an actual key? Was the ***** already in the field when you loaded the form or did you type it in manually?
It actualy means "Five asterisks" - there is no use case to put them in - but IMHO it should still not lead to a server error but be caught in input validation 
I could reproduce the error in `base/forms/__init__.py::118` – it is not directly related to input validation. The code assumes `payment_stripe_secret_key` always has an initial value. I will add a fix.

Resolving patch:
diff --git a/src/pretix/base/forms/__init__.py b/src/pretix/base/forms/__init__.py
--- a/src/pretix/base/forms/__init__.py
+++ b/src/pretix/base/forms/__init__.py
@@ -38,6 +38,7 @@
 from django import forms
 from django.forms.models import ModelFormMetaclass
 from django.utils.crypto import get_random_string
+from django.utils.translation import gettext_lazy as _
 from formtools.wizard.views import SessionWizardView
 from hierarkey.forms import HierarkeyForm
 
@@ -128,6 +129,12 @@ def clean(self):
         # at all, it will be considered a changed value and stored. We do not want that, as it makes it very hard to add
         # languages to an organizer/event later on. So we trick it and make sure nothing gets changed in that situation.
         for name, field in self.fields.items():
+            if isinstance(field, SecretKeySettingsField) and d.get(name) == SECRET_REDACTED and not self.initial.get(name):
+                self.add_error(
+                    name,
+                    _('Due to technical reasons you cannot set inputs, that need to be masked (e.g. passwords), to %(value)s.') % {'value': SECRET_REDACTED}
+                )
+
             if isinstance(field, i18nfield.forms.I18nFormField):
                 value = d.get(name)
                 if not value:


Test patch: