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

Python 3 code should check if avro.codec is None before decoding

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7.7, 1.8.2
    • Component/s: None
    • Labels:
      None

      Description

      I'm getting the error below when trying to read an Avro file in Python 3. FWIW, I generated this Avro file from Pig. I don't know if that makes a difference.

      avro.datafile.DataFileReader(open("test.avro","rb"),avro.io.DatumReader())
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/mhayes/.pyenv/versions/3.4.2/lib/python3.4/site-packages/avro/datafile.py", line 352, in __init__
          self.codec = self.GetMeta('avro.codec').decode('utf-8')
      AttributeError: 'NoneType' object has no attribute 'decode'
      

      It appears the problem is in the following code. It should check if GetMeta returns None before trying to decode it. The Python 2 code doesn't have this problem because it is already decoded.

          # ensure codec is valid
          self.codec = self.GetMeta('avro.codec').decode('utf-8')
          if self.codec is None:
            self.codec = "null"
          if self.codec not in VALID_CODECS:
            raise DataFileException('Unknown codec: %s.' % self.codec)
      

        Attachments

        1. AVRO-1741.diff
          0.6 kB
          Matthew Hayes

          Activity

            People

            • Assignee:
              mhayes Matthew Hayes
              Reporter:
              mhayes Matthew Hayes
            • Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: