Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-52875

IDL structs can't contain structs with field validators

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 5.0.0-rc0
    • Affects Version/s: None
    • Component/s: IDL
    • None
    • Fully Compatible
    • ALL
    • Repl 2020-11-16, Repl 2020-11-30

      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.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: