Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions openwisp_controller/subnet_division/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def rule_class(self):
return import_string(self.type)

def clean(self):
# Auto-fill organization from master subnet
if (
self.master_subnet_id
and self.master_subnet.organization_id is not None
and not self.organization_id
):
self.organization_id = self.master_subnet.organization_id
super().clean()
Comment on lines +72 to 79
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Add a regression test for the new organization inheritance branch.

Please add a model test that verifies: when master_subnet.organization_id is set and organization_id is empty, clean() sets organization_id before validation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openwisp_controller/subnet_division/base/models.py` around lines 72 - 79, Add
a model test that creates a master_subnet with organization_id set and a child
subnet/instance with master_subnet assigned and organization_id empty, then call
full_clean() (so clean() runs before validation) and assert that
instance.organization_id equals master_subnet.organization_id and no
ValidationError is raised; reference the model's clean() method and the fields
master_subnet and organization_id when locating the code to test.

self._validate_label()
self._validate_master_subnet_validity()
Expand Down
Loading