-
-
Notifications
You must be signed in to change notification settings - Fork 300
Fixed SubnetDivisionIndex foreign keys saved as NULL #1436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,7 +256,7 @@ def create_subnets(config, division_rule, max_subnet, generated_indexes): | |
| generated_indexes.append( | ||
| SubnetDivisionIndex( | ||
| keyword=f"{division_rule.label}_subnet{subnet_id}", | ||
| subnet_id=subnet_obj.id, | ||
| subnet=subnet_obj, | ||
| rule_id=division_rule.id, | ||
| config=config, | ||
| ) | ||
|
|
@@ -294,8 +294,8 @@ def create_ips(config, division_rule, generated_subnets, generated_indexes): | |
| generated_indexes.append( | ||
| SubnetDivisionIndex( | ||
| keyword=f"{subnet_obj.name}_ip{keyword_index}", | ||
| subnet_id=subnet_obj.id, | ||
| ip_id=ip_obj.id, | ||
| subnet=subnet_obj, | ||
| ip=ip_obj, | ||
|
Comment on lines
+297
to
+298
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, how is this different? |
||
| rule_id=division_rule.id, | ||
| config=config, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1050,6 +1050,48 @@ def test_invalid_master_subnet(self): | |
| e.message_dict.get("master_subnet", []), | ||
| ) | ||
|
|
||
| def test_subnet_division_index_integrity(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you check that this test fails on the current master? If yes, can you point out in the [issue comments[(https://github.com//issues/1435#issuecomment-4957428251) why the existing test cases are unable to detect the bug you reported? |
||
| rule = self._get_vpn_subdivision_rule() | ||
| self.config.templates.add(self.template) | ||
|
|
||
| # Verify initial indexes have non-NULL subnet_id and ip_id | ||
| # (if they are IP indexes) | ||
| indexes = rule.subnetdivisionindex_set.all() | ||
| self.assertTrue(indexes.exists()) | ||
| initial_count = indexes.count() | ||
| for index in indexes: | ||
| self.assertIsNotNone( | ||
| index.subnet_id, | ||
| f"SubnetDivisionIndex {index.keyword} has NULL subnet_id", | ||
| ) | ||
| if "_ip" in index.keyword: | ||
| self.assertIsNotNone( | ||
| index.ip_id, | ||
| f"SubnetDivisionIndex {index.keyword} has NULL ip_id", | ||
| ) | ||
|
|
||
| # Update number of IPs to trigger tasks.provision_extra_ips | ||
| rule.number_of_ips = rule.number_of_ips + 2 | ||
| rule.save() | ||
| rule.refresh_from_db() | ||
|
|
||
| # Verify count increased and all indexes, including new ones, | ||
| # have non-NULL subnet_id and ip_id | ||
| new_indexes = rule.subnetdivisionindex_set.all() | ||
| self.assertEqual( | ||
| new_indexes.count(), initial_count + (rule.number_of_subnets * 2) | ||
| ) | ||
| for index in new_indexes: | ||
| self.assertIsNotNone( | ||
| index.subnet_id, | ||
| f"SubnetDivisionIndex {index.keyword} has NULL subnet_id after update", | ||
| ) | ||
| if "_ip" in index.keyword: | ||
| self.assertIsNotNone( | ||
| index.ip_id, | ||
| f"SubnetDivisionIndex {index.keyword} has NULL ip_id after update", | ||
| ) | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| class TestOpenVPNSubnetDivisionRule( | ||
| SubnetDivisionTestMixin, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this different?