-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Server Programmability
-
ALL
-
None
-
3
-
None
-
None
-
None
-
None
-
None
-
None
If you create an IDL struct that has a field with type variant-of-structs, IDL will refuse to compile it with an error ID0081 unless each struct in the variant has a unique first field. This is to avoid ambiguity when parsing the subdocument.
However, in the case where IDL does compile your struct, it generates code that relies on the fields in the variant subdocument being ordered. For example, consider this IDL:
structs: Foo: description: "foo" fields: fieldFoo: type: int fieldCommon: type: int Bar: description: "bar" fields: fieldBar: type: int fieldCommon: type: int FooOrBar: description: "foo or bar" fields: fieldFooOrBar: type: variant: [Foo, Bar]
It will compile, and will successfully parse a BSON document like:
{fieldFooOrBar: {fieldBar: 1, fieldCommon: 2}}
but not a similar document with the fields reordered:
{fieldFooOrBar: {fieldCommon: 2, fieldBar: 1}}
This is a footgun since the second document is a valid document of type Bar. One possible fix is to add an ordered field to IDL structs and only support variant-of-structs where all of the structs have ordered: true. Another possibility is to remove the variant-of-structs feature altogether and use a different approach where it's currently used.
- is related to
-
SERVER-73138 Support variants of complex types in IDL
-
- Closed
-
-
SERVER-84122 Document that IDL struct variants impose constraint on field ordering
-
- Closed
-