Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1848

Can't use null or false defaults in Ruby

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 1.8.0
    • 1.8.2
    • ruby
    • Any

    • Important

    Description

      When calling to_avro on an Avro::Schema::Field instance (part of calling to_avro on an instance of Avro::Schema::RecordSchema), it will not include the default value definition if the default value is falsey.

      The offending code is:

            def to_avro(names=Set.new)
              {'name' => name, 'type' => type.to_avro(names)}.tap do |avro|
                avro['default'] = default if default
                avro['order'] = order if order
              end
            end
      

      Using the if default conditional predicate here is inappropriate, as is relying on nil values to represent no default, because null in JSON maps to nil in Ruby.

      This is a critical show-stopper to using AvroTurf with the Confluent Schema Registry because it is quietly uploading incorrect schemas, causing downstream readers to behave incorrectly and also causing the schema registry to reject new schema versions as incompatible when they are actually just fine if the falsey default values are included when submitting the schema to the registry.

      Attachments

        Issue Links

          Activity

            People

              theturtle32 Brian McKelvey
              theturtle32 Brian McKelvey
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 2h
                  2h
                  Remaining:
                  Remaining Estimate - 2h
                  2h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified