Skip to content

Commit 21c1fb1

Browse files
committed
[fix] Fix Device.organization.RelatedObjectDoesNotExist error and improve test
1 parent 76cb583 commit 21c1fb1

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ jobs:
9494
GECKO_LOG: 1
9595

9696
- name: Show gecko web driver log on failures
97-
if: ${{ failure() }}
98-
run: cat geckodriver.log
97+
if: ${{ failure() && steps.deps.conclusion == 'success' }}
98+
run: |
99+
if [ -f geckodriver.log ]; then
100+
cat geckodriver.log
101+
else
102+
echo "geckodriver.log not found"
103+
fi
99104
100105
- name: Upload Coverage
101106
if: ${{ success() }}

openwisp_controller/config/base/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,9 @@ def clean_templates_org(cls, action, instance, pk_set, raw_data=None, **kwargs):
415415
pk_list = [template.pk for template in templates]
416416
templates = template_model.objects.filter(pk__in=pk_list)
417417
# looking for invalid templates
418-
organization = raw_data.get("organization", instance.device.organization)
418+
organization = raw_data.get("organization") or getattr(
419+
instance.device, "organization", None
420+
)
419421
invalids = (
420422
templates.exclude(organization=organization)
421423
.exclude(organization=None)

openwisp_controller/config/tests/test_admin.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,18 +2281,20 @@ def test_templates_fetch_queries_10(self):
22812281

22822282
def test_empty_device_form_with_config_inline(self):
22832283
"""
2284-
Test for issue #1057: MultiValueDictKeyError when submitting
2285-
empty device form with configuration inline added
2284+
Ensures submitting device form with missing required fields
2285+
and configuration inline shows validation errors instead of
2286+
raising an exception
22862287
"""
22872288
org = self._get_org()
2289+
template = self._create_template(organization=org)
22882290
path = reverse(f"admin:{self.app_label}_device_add")
2289-
# Submit empty form with config inline
2291+
# Submit form without required device fields but with config inline
2292+
# This reproduces the scenario where user clicks "Add another Configuration"
2293+
# and submits without filling device details
22902294
params = {
2291-
"name": "",
2292-
"mac_address": "",
2293-
"organization": "",
2295+
"organization": str(org.pk),
22942296
"config-0-backend": "netjsonconfig.OpenWrt",
2295-
"config-0-templates": "",
2297+
"config-0-templates": str(template.pk),
22962298
"config-0-config": json.dumps({}),
22972299
"config-0-context": "",
22982300
"config-TOTAL_FORMS": 1,

0 commit comments

Comments
 (0)