{"action":"created","issue":{"url":"https://api.github.com/repos/graphql-python/graphene-django/issues/67","repository_url":"https://api.github.com/repos/graphql-python/graphene-django","labels_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/67/labels{/name}","comments_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/67/comments","events_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/67/events","html_url":"https://github.com/graphql-python/graphene-django/issues/67","id":191555266,"number":67,"title":"Choice fields automatically converted to enums","user":{"login":"kaglowka","id":6314663,"avatar_url":"https://avatars.githubusercontent.com/u/6314663?v=3","gravatar_id":"","url":"https://api.github.com/users/kaglowka","html_url":"https://github.com/kaglowka","followers_url":"https://api.github.com/users/kaglowka/followers","following_url":"https://api.github.com/users/kaglowka/following{/other_user}","gists_url":"https://api.github.com/users/kaglowka/gists{/gist_id}","starred_url":"https://api.github.com/users/kaglowka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaglowka/subscriptions","organizations_url":"https://api.github.com/users/kaglowka/orgs","repos_url":"https://api.github.com/users/kaglowka/repos","events_url":"https://api.github.com/users/kaglowka/events{/privacy}","received_events_url":"https://api.github.com/users/kaglowka/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-24T16:08:40Z","updated_at":"2016-11-25T09:32:12Z","closed_at":null,"body":"```python\r\nclass User(DjangoObjectType):\r\n    class Meta:\r\n        model = get_user_model()\r\n        only_fields = ['signup_site_version']\r\n\r\nclass Query(graphene.ObjectType):\r\n    user = graphene.Field(User)\r\n\r\n    def resolve_user(self, args, context, info):\r\n        return user_from_info(info)  # return django user from context\r\n```\r\n\r\n### User model:\r\n```python\r\n@python_2_unicode_compatible\r\nclass User(AbstractUser):\r\n    (...)\r\n    signup_site_version_choices = [(1, u'site 1'), (2, u'site 2')]\r\n    signup_site_version = models.IntegerField(choices=signup_site_version_choices)\r\n```\r\n\r\n### Query\r\n```\r\nquery { \r\n  user {\r\n    signupSiteVersion\r\n  }\r\n}\r\n```\r\n\r\n### Result\r\n```json\r\n{\r\n  \"data\": {\r\n    \"user\": {\r\n      \"signupSiteVersion\": \"A_1\"\r\n    }\r\n  }\r\n}\r\n\r\n```\r\n\r\nA copy-paste from where the weird value is born:\r\n```python\r\ndef convert_choice_name(name):\r\n    name = to_const(force_text(name))\r\n    try:\r\n        assert_valid_name(name)\r\n    except AssertionError:\r\n        name = \"A_%s\" % name\r\n    return name\r\n```\r\n\r\nWe've had similar problems in the old graphene (< 1.0): https://github.com/graphql-python/graphene/issues/134\r\nThe output is \"A_1\", because the field converter assumes django choices are tuples (id, name) where name is a constant name (not containing spaces etc.) or is convertible to a valid constant name. For some reason it is not successful while doing that for \"site 1\", but that is not an issue. The problem is it assumes we would like to do that.\r\nIn our django application (I suppose it is the norm) we use the second tuple element as a human-readable label. It means that in most cases replacing space with an underscore will do the work, but\r\nin the other names are still bound to be long and there is no character we can safely assume the name won't contain (including hyphens, all native character varieties etc.).\r\nThe Enum fields are certainly nice, as their values are schema-validated, to say the least, but I doubt automatic conversion should be the only possible behaviour."},"comment":{"url":"https://api.github.com/repos/graphql-python/graphene-django/issues/comments/262915591","html_url":"https://github.com/graphql-python/graphene-django/issues/67#issuecomment-262915591","issue_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/67","id":262915591,"user":{"login":"mjtamlyn","id":389581,"avatar_url":"https://avatars.githubusercontent.com/u/389581?v=3","gravatar_id":"","url":"https://api.github.com/users/mjtamlyn","html_url":"https://github.com/mjtamlyn","followers_url":"https://api.github.com/users/mjtamlyn/followers","following_url":"https://api.github.com/users/mjtamlyn/following{/other_user}","gists_url":"https://api.github.com/users/mjtamlyn/gists{/gist_id}","starred_url":"https://api.github.com/users/mjtamlyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjtamlyn/subscriptions","organizations_url":"https://api.github.com/users/mjtamlyn/orgs","repos_url":"https://api.github.com/users/mjtamlyn/repos","events_url":"https://api.github.com/users/mjtamlyn/events{/privacy}","received_events_url":"https://api.github.com/users/mjtamlyn/received_events","type":"User","site_admin":false},"created_at":"2016-11-25T09:32:12Z","updated_at":"2016-11-25T09:32:12Z","body":"My personal opinion is that it should be easy to make choices an Enum, but that it shouldn't be the default. The requirements of django choices are much, much more permissive than those of an Enum (in either Python or GraphQL)"}}
{"actor":{"display_login":"mjtamlyn"}}