mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-15 08:12:18 -06:00
Fixes #21045: Allow saving Site with associated Prefix
Some checks failed
CI / build (20.x, 3.12) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
CI / build (20.x, 3.10) (push) Has been cancelled
CI / build (20.x, 3.11) (push) Has been cancelled
Lock threads / lock (push) Has been cancelled
Close stale issues/PRs / stale (push) Has been cancelled
Close incomplete issues / stale (push) Has been cancelled
Update translation strings / makemessages (push) Has been cancelled
Some checks failed
CI / build (20.x, 3.12) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
CI / build (20.x, 3.10) (push) Has been cancelled
CI / build (20.x, 3.11) (push) Has been cancelled
Lock threads / lock (push) Has been cancelled
Close stale issues/PRs / stale (push) Has been cancelled
Close incomplete issues / stale (push) Has been cancelled
Update translation strings / makemessages (push) Has been cancelled
This was a result of the fix for #20944 optimizing a query to only include the `id` field with `.only(id)`. Since `Prefix.__init__()` caches original values from other fields (`_prefix` and `_vrf_id`), these cached values are `None` at init-time. This might not normally be a problem, but the sequence of events in the bug report also end up causing the `handle_prefix_saved` handler to run, which uses an ORM lookup, (either `net_contained_or_equal` original`net_contained`) that does not support a query argument of `None`.
This commit is contained in:
committed by
Jeremy Stretch
parent
3813aad8b1
commit
914653d63e
@@ -210,7 +210,7 @@ def sync_cached_scope_fields(instance, created, **kwargs):
|
|||||||
for model in (Prefix, Cluster, WirelessLAN):
|
for model in (Prefix, Cluster, WirelessLAN):
|
||||||
qs = model.objects.filter(**filters)
|
qs = model.objects.filter(**filters)
|
||||||
|
|
||||||
for obj in qs.only('id'):
|
for obj in qs:
|
||||||
# Recompute cache using the same logic as save()
|
# Recompute cache using the same logic as save()
|
||||||
obj.cache_related_objects()
|
obj.cache_related_objects()
|
||||||
obj.save(update_fields=[
|
obj.save(update_fields=[
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from core.models import ObjectType
|
|||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.models import *
|
from dcim.models import *
|
||||||
from extras.models import CustomField
|
from extras.models import CustomField
|
||||||
|
from ipam.models import Prefix
|
||||||
from netbox.choices import WeightUnitChoices
|
from netbox.choices import WeightUnitChoices
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.data import drange
|
from utilities.data import drange
|
||||||
@@ -1192,3 +1193,14 @@ class VirtualChassisTestCase(TestCase):
|
|||||||
device2.vc_position = 1
|
device2.vc_position = 1
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
device2.full_clean()
|
device2.full_clean()
|
||||||
|
|
||||||
|
|
||||||
|
class SiteSignalTestCase(TestCase):
|
||||||
|
|
||||||
|
@tag('regression')
|
||||||
|
def test_edit_site_with_prefix_no_vrf(self):
|
||||||
|
site = Site.objects.create(name='Test Site', slug='test-site')
|
||||||
|
Prefix.objects.create(prefix='192.0.2.0/24', scope=site, vrf=None)
|
||||||
|
|
||||||
|
# Regression test for #21045: should not raise ValueError
|
||||||
|
site.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user