Skip to content

Commit cc5acd8

Browse files
authored
Fix the order of fields in Protobuf (#530)
Previously, we relied on the order of ``set`` for the fields in Protobuf. This is dangerous as the order of ``set`` is not well-defined across different Python versions and implementations. To avoid potential bugs in the future, we fix the fields to correspond with the order of properties in the class. Note that this solution is also not completely future proof. If you add properties in the middle of a class, the field IDs in protocol buffers will change causing incompatibility between the two Protocol Buffer definitions.
1 parent b800727 commit cc5acd8

File tree

4 files changed

+1123
-1127
lines changed
  • aas_core_codegen/protobuf/structure
  • test_data/proto/test_main/expected
    • aas_core_meta.v3/expected_output
    • abstract_and_concrete_classes/expected_output
    • concrete_class_with_primitive_attributes/expected_output

4 files changed

+1123
-1127
lines changed

aas_core_codegen/protobuf/structure/_generate.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,7 @@ def _generate_class(
309309
required_choice_object = [] # type: List[intermediate.AbstractClass]
310310

311311
# region Getters and setters
312-
for i, prop in enumerate(
313-
set(cls.properties).union(
314-
set(cls.interface.properties if cls.interface is not None else [])
315-
)
316-
):
312+
for i, prop in enumerate(cls.properties):
317313
prop_type = proto_common.generate_type(type_annotation=prop.type_annotation)
318314

319315
prop_name = proto_naming.property_name(prop.name)

0 commit comments

Comments
 (0)