diff --git a/src/context/service/database/Link.py b/src/context/service/database/Link.py index afebbb53756c3910cd51cc00ba2c0fea771e3cb2..4ca3cee68e45cc9b5a8f4e0d9f1b07a3ec39f268 100644 --- a/src/context/service/database/Link.py +++ b/src/context/service/database/Link.py @@ -102,7 +102,8 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) total_capacity_gbps, used_capacity_gbps = None, None if request.HasField('attributes'): attributes = request.attributes - attribute_names = set([field.name for field in attributes._fields]) + # In proto3, HasField() does not work for scalar fields, using ListFields() instead. + attribute_names = set([field.name for field,_ in attributes.ListFields()]) if 'total_capacity_gbps' in attribute_names: total_capacity_gbps = attributes.total_capacity_gbps if 'used_capacity_gbps' in attribute_names: diff --git a/src/context/tests/test_link.py b/src/context/tests/test_link.py index d27ff6e4aa31cdb55762a403fe0bfc6a154ce99e..8b07f0230cc12add4ab0f2db78f3663cb021ca3a 100644 --- a/src/context/tests/test_link.py +++ b/src/context/tests/test_link.py @@ -96,7 +96,8 @@ def test_link(context_client : ContextClient) -> None: assert response.name == LINK_R1_R2_NAME assert len(response.link_endpoint_ids) == 2 assert response.HasField('attributes') - attribute_names = set([field.name for field in response.attributes._fields]) + # In proto3, HasField() does not work for scalar fields, using ListFields() instead. + attribute_names = set([field.name for field,_ in response.attributes.ListFields()]) assert 'total_capacity_gbps' in attribute_names assert abs(response.attributes.total_capacity_gbps - 100) < 1.e-12 assert 'used_capacity_gbps' in attribute_names @@ -134,7 +135,8 @@ def test_link(context_client : ContextClient) -> None: assert response.name == new_link_name assert len(response.link_endpoint_ids) == 2 assert response.HasField('attributes') - attribute_names = set([field.name for field in response.attributes._fields]) + # In proto3, HasField() does not work for scalar fields, using ListFields() instead. + attribute_names = set([field.name for field,_ in response.attributes.ListFields()]) assert 'total_capacity_gbps' in attribute_names assert abs(response.attributes.total_capacity_gbps - 200) < 1.e-12 assert 'used_capacity_gbps' in attribute_names @@ -152,9 +154,11 @@ def test_link(context_client : ContextClient) -> None: assert len(response.links[0].link_endpoint_ids) == 2 assert len(response.links[0].link_endpoint_ids) == 2 assert response.links[0].HasField('attributes') - assert response.links[0].attributes.HasField('total_capacity_gbps') + # In proto3, HasField() does not work for scalar fields, using ListFields() instead. + attribute_names = set([field.name for field,_ in response.links[0].attributes.ListFields()]) + assert 'total_capacity_gbps' in attribute_names assert abs(response.links[0].attributes.total_capacity_gbps - 200) < 1.e-12 - assert response.links[0].attributes.HasField('used_capacity_gbps') + assert 'used_capacity_gbps' in attribute_names assert abs(response.links[0].attributes.used_capacity_gbps - 50) < 1.e-12 # ----- Check relation was created ---------------------------------------------------------------------------------