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

Nameless schema should raise AttributeError when attempting to access name

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.9.0
    • Component/s: python
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      In the "py" implementation, this works as expected:

      >>> from avro.schema import parse
      >>> s = parse('{"type": "array", "items": "int"}')
      >>> s.name
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      AttributeError: 'ArraySchema' object has no attribute 'name'

      but in the py3 implementation, a NameError is raised instead:

      >>> from avro.schema import Parse
      >>> s=Parse('{"type":"array","items":"int"}')
      >>> s.name
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/michaels/dev/avro/lang/py3/avro/schema.py", line 224, in name
      return self._props['name']
      KeyError: 'name'

      This behavior breaks several python idioms, including the ability to get a default value using getattr:

      >>> getattr(s, "name", "default")
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/michaels/dev/avro/lang/py3/avro/schema.py", line 224, in name
      return self._props['name']
      KeyError: 'name'

      I will open a PR with tests and a fix.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kojiromike Michael A. Smith
                Reporter:
                kojiromike Michael A. Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: