Skip to content

Commit 1e92a71

Browse files
thangphan205claude
andcommitted
fix: don't clobber unset interface fields on partial update
update_interface dumped the full InterfaceUpdate model without exclude_unset, so any partial update (e.g. description only) sent None for every other field including port, tripping interface.port's NOT NULL constraint and 500ing. Now the DB write only applies fields the caller actually sent; configure_interface still gets the full merged state since it indexes port/mode/etc unconditionally. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 847dd05 commit 1e92a71

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

backend/app/crud/interfaces.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,22 @@ def update_interface(
108108
"""
109109
Update an interface.
110110
"""
111-
# update local database
112-
update_dict = interface_in.model_dump()
111+
# update local database — only touch fields the caller actually sent,
112+
# so omitted fields (e.g. port) don't get clobbered with None
113+
update_dict = interface_in.model_dump(exclude_unset=True)
113114
update_dict["updated_at"] = datetime.now()
114115
interface_db.sqlmodel_update(update_dict)
115116
session.add(interface_db)
116117
session.commit()
117118
session.refresh(interface_db)
118-
# update running config
119+
# update running config — configure_interface needs the full merged
120+
# state (existing values + whatever changed), not just what was sent
121+
full_dict = interface_db.model_dump()
119122
if update_running_config:
120-
configure_interface(switch=switch, interface_info=update_dict)
123+
configure_interface(switch=switch, interface_info=full_dict)
121124
# Reflect configured VLAN list back into DB so Current State stays accurate
122-
if update_dict.get("mode") == "trunk" and update_dict.get("allowed_vlan_add"):
123-
interface_db.allowed_vlan = update_dict["allowed_vlan_add"]
125+
if full_dict.get("mode") == "trunk" and full_dict.get("allowed_vlan_add"):
126+
interface_db.allowed_vlan = full_dict["allowed_vlan_add"]
124127
session.add(interface_db)
125128
session.commit()
126129
session.refresh(interface_db)

0 commit comments

Comments
 (0)