-
Notifications
You must be signed in to change notification settings - Fork 106
Description
livekit-api: 1.0.5
Python: 3.11
Attempting to update existing inbound SIP Trunk numbers or allowed fails using update_sip_inbound_trunk_fields. The example on the livekit docs page fails as well.
async def update_inbound_trunk_numbers():
"""
Add a phone number to an existing trunk.
"""
livekit_api = api.LiveKitAPI()
trunk_id = "redacted"
trunk = await livekit_api.sip.update_sip_inbound_trunk_fields(
trunk_id=trunk_id,
allowed_numbers=["+13105550100", "+17145550100"],
name="My updated trunk",
)
print("Updated inbound trunk numbers:", trunk)
await livekit_api.aclose()
Calling LiveKitAPI.sip.update_sip_inbound_trunk_fields(..., numbers=[...]) (and the outbound equivalent) crashes with:
AttributeError: Assignment not allowed to message field "numbers" in protocol message object.
The helper constructs a SIPInboundTrunkUpdate and then assigns a ListUpdate to a message-typed field (update.numbers = ListUpdate(set=...)). In Python protobuf, message fields must be set via CopyFrom(...), not direct assignment.
# in SipService.update_sip_inbound_trunk_fields(...)
update = SIPInboundTrunkUpdate(
auth_username=auth_username,
auth_password=auth_password,
name=name,
metadata=metadata,
)
if numbers is not None:
update.numbers = ListUpdate(set=numbers) # <- crashes
The outbound helper does the same for update.numbers.
In Python’s protobuf API you cannot assign a sub-message directly; you must call .CopyFrom(...) (or mutate the existing message). This is longstanding protobuf behavior.
I looked into the community slack channel and others have had this issue as well (only with suggestions to update via the WebUI) and didn't see a similar issue posted in Github.