You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/05/30 02:53:00 UTC

[jira] [Commented] (AVRO-2183) Nameless schema should raise AttributeError when attempting to access name

    [ https://issues.apache.org/jira/browse/AVRO-2183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16494611#comment-16494611 ] 

ASF GitHub Bot commented on AVRO-2183:
--------------------------------------

kojiromike opened a new pull request #313: AVRO-2183 Provide name only for named schema
URL: https://github.com/apache/avro/pull/313
 
 
   Otherwise, allow python to raise an AttributeError

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Nameless schema should raise AttributeError when attempting to access name
> --------------------------------------------------------------------------
>
>                 Key: AVRO-2183
>                 URL: https://issues.apache.org/jira/browse/AVRO-2183
>             Project: Avro
>          Issue Type: Bug
>          Components: python
>            Reporter: Michael A. Smith
>            Priority: Major
>
> In the "py" implementation, this works as expected:
> {noformat}
> >>> 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'{noformat}
> but in the py3 implementation, a {{NameError}} is raised instead:
> {noformat}
> >>> 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'{noformat}
> This behavior breaks several python idioms, including the ability to get a default value using {{getattr}}:
> {noformat}
> >>> 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'{noformat}
> I will open a PR with tests and a fix.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)