[SERVER-52875] IDL structs can't contain structs with field validators Created: 16/Nov/20  Updated: 29/Oct/23  Resolved: 16/Nov/20

Status: Closed
Project: Core Server
Component/s: IDL
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: Bug Priority: Minor - P4
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Repl 2020-11-16, Repl 2020-11-30
Participants:

 Description   

An IDL file like the following will produce C++ code that cannot compile:

structs:
    int_basic_ranges:
        description: Struct using basic range validators on ints
        fields:
            positive_int:
                type: int
                validator: { gt: 0 }
 
    chained_callback_validators:
        description: Uses a chained struct that includes fields with validators
        chained_structs:
            int_basic_ranges: int_basic_ranges

The generated Chained_callback_validators class will define the required validatePositive_int() method in its cpp file, but it will not declare the method in its header, leading to a compilation error.

The following rule in generator.py's _CppHeaderFileWriter.generate is to blame:

                    if [field for field in struct.fields if field.validator]:
                        self.write_unindented_line('private:')
                        for field in struct.fields:
                            if not field.ignore and not struct.immutable and \
                                not field.chained_struct_field and field.validator:
                                self.gen_validators(field)

We have no IDL structs today that include structs with field validators. (I discovered the problem while creating such a struct, then changed my mind about whether I needed that struct.) Let's fix the bug anyway, while we understand it.



 Comments   
Comment by Githook User [ 16/Nov/20 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-52875 Let IDL structs include structs with field validators
Branch: master
https://github.com/mongodb/mongo/commit/55dc4222382b19547fc1d3657bd78e51297c2711

Generated at Thu Feb 08 05:29:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.