Skip to content

Commit 3b3a997

Browse files
authored
Merge pull request #37 from kpetremann/main
fix(api): safi disappearing for PATCH requests
2 parents 69e4965 + 6335c28 commit 3b3a997

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

netbox_cmdb/netbox_cmdb/api/bgp/serializers.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def update(self, instance, validated_data):
189189
bgp_peers["peer_b"] = DeviceBGPSession.objects.get(peer_b=instance)
190190
for peer, peer_instance in bgp_peers.items():
191191
# pop afi safi data for later creation/update
192-
afi_safis_data[peer] = peers_data[peer].pop("afi_safis", {})
192+
afi_safis_data[peer] = peers_data[peer].pop("afi_safis", None)
193193

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

219+
# handle safi
220+
if afi_safis_data[peer] is None:
221+
# useful for PATCH requests: if the field is empty, we don't change anything
222+
continue
223+
219224
# get current list of afi safi
220225
current_afi_safis = list(AfiSafi.objects.filter(device_bgp_session=peer_instance))
221226
current_afi_safi_mapping = {

0 commit comments

Comments
 (0)