Skip to content

Commit

Permalink
Fix incorrect handling of non-existent scopes
Browse files Browse the repository at this point in the history
The old code seemed to assume that `scope` would be `None` if no
`Prefix` matching the network address could be found in the DB.  But,
of course, Django raises a `DoesNotExist` exception when using
`Prefix.objects.get()` for this purpose.

This changes the logic to catch the exception, but otherwise produce
the originally intended response.
  • Loading branch information
lunkwill42 committed Sep 19, 2024
1 parent 1f4e4ee commit cedfaee
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/nav/web/ipam/prefix_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ def make_tree(prefixes, family=None, root_ip=None, show_all=None, sort_by="ip"):
init = []

if root_ip is not None and root_ip:
scope = Prefix.objects.get(net_address=root_ip)
if scope is not None:
try:
scope = Prefix.objects.get(net_address=root_ip)
node = PrefixNode(scope)
else:
except Prefix.DoesNotExist:
node = FauxNode(root_ip, "scope", "scope")
init.append(node)

Expand Down

0 comments on commit cedfaee

Please sign in to comment.