Skip to content

Commit

Permalink
Merge pull request #37 from kpetremann/main
Browse files Browse the repository at this point in the history
fix(api): safi disappearing for PATCH requests
  • Loading branch information
kpetremann authored Aug 1, 2024
2 parents 69e4965 + 6335c28 commit 3b3a997
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion netbox_cmdb/netbox_cmdb/api/bgp/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def update(self, instance, validated_data):
bgp_peers["peer_b"] = DeviceBGPSession.objects.get(peer_b=instance)
for peer, peer_instance in bgp_peers.items():
# pop afi safi data for later creation/update
afi_safis_data[peer] = peers_data[peer].pop("afi_safis", {})
afi_safis_data[peer] = peers_data[peer].pop("afi_safis", None)

# update peer instance with provided data
peer_instance.device = peers_data[peer].get("device", peer_instance.device)
Expand All @@ -216,6 +216,11 @@ def update(self, instance, validated_data):
)
peer_instance.save()

# handle safi
if afi_safis_data[peer] is None:
# useful for PATCH requests: if the field is empty, we don't change anything
continue

# get current list of afi safi
current_afi_safis = list(AfiSafi.objects.filter(device_bgp_session=peer_instance))
current_afi_safi_mapping = {
Expand Down

0 comments on commit 3b3a997

Please sign in to comment.