From cced434a99315894421690cf763ae18c22426e5a Mon Sep 17 00:00:00 2001 From: Adarnof Date: Tue, 17 Jan 2017 23:49:55 -0500 Subject: [PATCH] Correct API key form validation errors. If an individual field fails, its value gets removed from the cleaned_data dict, but the full form clean() method still gets called. As this form checks for api_id and api_key in the dict upon clean(), it would raise an unhandled KeyError --- eveonline/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eveonline/forms.py b/eveonline/forms.py index a403daae..efffdbc7 100644 --- a/eveonline/forms.py +++ b/eveonline/forms.py @@ -28,7 +28,10 @@ class UpdateKeyForm(forms.Form): raise forms.ValidationError("API ID must be a number") def clean(self): - super(UpdateKeyForm, self).clean() + if 'api_id' not in self.cleaned_data or 'api_key' not in self.cleaned_data: + # need to check if api_id and vcode in cleaned_data because + # if they fail, they get removed from the dict but this method still happens + return self.cleaned_data if EveManager.check_if_api_key_pair_exist(self.cleaned_data['api_id']): logger.debug("UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data['api_id'])