Skip to content

Charfield choice with blank=True fix #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Charfield choice with blank=True fix #525

wants to merge 2 commits into from

Conversation

legios89
Copy link

@legios89 legios89 commented Sep 25, 2018

Hi,
I just found this problem during my work, and also found the solution in the following issue: #503
I also modified tests, what I forget to do in the previous pull request.

@coveralls
Copy link

coveralls commented Sep 25, 2018

Coverage Status

Coverage increased (+0.02%) to 94.537% when pulling dd1e169 on vertisfinance:charfield_choice_blank_fix into f76f38e on graphql-python:master.

@legios89
Copy link
Author

I am a little bit confused about what this error means? For me, it looks like everything went fine.

@legios89 legios89 closed this Sep 26, 2018
@patrick91
Copy link
Member

Hi @legios89 why did you close this? I think it is quite good, my only doubt would be that we are returning an empty string where it might make more sense to return None (just thinking from a frontend perspective).

Anyway, I've attached a test case that you can put in the PR, might be worth merging this and closing #474 :)

@spockNinja @syrusakbary do you have any additional feedback on this?

# https://github.com/graphql-python/graphene-django/issues/474

import graphene
from graphene_django import DjangoObjectType
from django.db import models

class Car(models.Model):
    class Meta:
        app_label = 'app'

    choice = models.CharField(
        choices=[('blue', 'Blue'), ('green', 'Green')],
        max_length=20,
        blank=True
    )

class CarNode(DjangoObjectType):
    class Meta:
        model = Car

def test_blank_choice():

    class Query(graphene.ObjectType):
        car = graphene.Field(CarNode)

        def resolve_car(self, info):
            return Car(choice="")

    schema = graphene.Schema(query=Query)
    result = schema.execute('{ car { choice } }')

    print(result.data, result.errors)

    assert not result.errors

@zbyte64
Copy link
Collaborator

zbyte64 commented Jun 3, 2019

I too am confused as to why this is closed. This is still an issue and the PR seemed reasonable. The only thing I would change is the choice label for the null/empty value. With this PR it will generate "A_" for the enum label when it should likely be "BLANK" or "NULL"

I want to reopen this but only if the @legios89 agrees. Otherwise we need to make our own PR or merge with #654

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants