Fix MultiValueDictKeyError on empty device form submission 1057
Checklist
- [x] I have read the OpenWISP Contributing Guidelines.
- [x] I have manually tested the changes proposed in this pull request.
- [x] I have written new test cases for new code and/or updated existing tests for changes to existing code.
- [ ] I have updated the documentation.
Reference to Existing Issue
Closes #1057
Description of Changes
Fixed the MultiValueDictKeyError that happened when you click "Add another Configuration" on a new device and hit save without filling anything in.
The problem was in the ConfigForm.get_temp_model_instance() method - it was trying to access organization, name, and mac_address from the form data without checking if they exist first. Changed it to use .get() so it handles empty fields properly and shows validation errors instead of crashing.
Added a test case to verify the fix works.
Screenshot
See issue #1057 for the error screenshot. After the fix, the form now shows proper validation errors instead of crashing.
Hey @DragnEmperor , really sorry for the inconvenience, I had to fix the commit message format to match the project guidelines (added the [fix] prefix). Could you approve the workflow one more time? should be good to go now.
coverage: 98.608% (+0.001%) from 98.607% when pulling 81f0780b62be472630e797fe09d5ffc5055b390f on Srinath0916:fix-multivaluedictkeyerror-1057 into aa2561fc452cd91a96b416bfeb565bc7a029fb38 on openwisp:master.
Hi @pandafy , @DragnEmperor , all checks are passing now, This PR is ready for review.
Hi @pandafy , @DragnEmperor , all checks are passing now, This PR is ready for review.
Hi @Srinath0916 , I would suggest to have a look once again through all the changes done to ensure any unrelated changes are not there. I see some changes in workflow yaml file.
Thanks @DragnEmperor ! I've reviewed all changes in this PR,
The MultiValueDictKeyError fix includes: - config/admin.py (the main fix) - config/base/config.py (related changes) - config/tests/test_admin.py (test for the fix)
The workflow yaml changes include: - Geckodriver logging removal (as you said) and Python 3.9 related changes from updating with master (PR #1174)
Should I clean up the workflow file to keep only the geckodriver removal you asked for and remove the Python 3.9 changes? I want to make sure the tests still pass."
Thanks @DragnEmperor ! I've reviewed all changes in this PR,
The MultiValueDictKeyError fix includes: - config/admin.py (the main fix) - config/base/config.py (related changes) - config/tests/test_admin.py (test for the fix)
The workflow yaml changes include: - Geckodriver logging removal (as you said) and Python 3.9 related changes from updating with master (PR #1174)
Should I clean up the workflow file to keep only the geckodriver removal you asked for and remove the Python 3.9 changes? I want to make sure the tests still pass."
@Srinath0916 I meant to keep the ci.yml as it is, no changes at all, currently I see there is some removal of code
Thanks @DragnEmperor ! I've reverted ci.yml to match master exactly. Now the PR contains only the MultiValueDictKeyError fix files with no workflow changes. Ready for review!
LGTM
Thank you @DragnEmperor , Really appreciate your patience and detailed feedback throughout this process.
Hi @pandafy , This PR has been approved, and all checks are passing. Could you help merge it when you get a chance? Thanks.