-
Notifications
You must be signed in to change notification settings - Fork 766
Django choice fields cannot be blank, even if field is not required -- graphene-django 2.1.0 / graphql-core 2.1 regression #474
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
Comments
I am experiencing the same thing - only started noticing it Monday morning when we got in - Friday it was working perfectly. Thank you for opening this @picturedots. |
It seems like the real issue is with graphql-core 2.1 -- I've tried to track down the issue a bit and added an issue there. |
Thank you @picturedots. I'll chime in. |
I wasn't able to reproduce this, here's a test case:
|
@sciyoshi This is happening for CharField's, not IntegerField's (as far as I can tell, since I don't have IntegerField's in my application). The major difference I am noticing is that for CharFields, they must be blank=True instead of null=True. @picturedots is your myChoicesField a CharField or some other field? |
@atomboulian Yes I can confirm that it's a CharField, For example, I have a field defined like
I get the error whenever fetching "payment_frequency" and there is a blank or null value for that object. I also get the error if |
Yep, exactly. |
@sciyoshi I'm having this issue as well. The code below will give me an error saying
If I add a If I add an empty string to the choices like this:
|
@ikedumancas Yep not good to put We should be able to use I was curious about trying the empty string case as you did. You're literally getting "A_" in your responses that have an empty string though? Can you post your response? That is so weird! Thanks for posting! |
@atomboulian Yeah. It's weird. It has to do with this code in |
I've experienced the issue with |
Hi @picturedots, I have tried your solution but still the error reported. |
The same error as reported is also an issue with graphene-django 2.2.0 |
I believe the root issue here is that graphene-django uses the MyEnum = Enum('MyEnum', {'':'---'}) # The Enum lib errors when trying to initialize an empty string as the name. My workaround solution for this is to comment out the code that generates the enums and just use raw def convert_django_field_with_choices(field, registry=None):
if registry is not None:
converted = registry.get_converted_field(field)
if converted:
return converted
converted = convert_django_field(field, registry)
if registry is not None:
registry.register_converted_field(field, converted)
return converted |
@bk-equityzen I am also thinking about creating a workaround that will create a value in the enumeration that represents blank, but would then be converted into an actual blank value after being processed by graphene (possibly in the the model's save or clean method.) . Will post here if I get something working. |
I was looking into the same but it more correctly might be somewhere in the grapql-core code to change |
I'm curious what the thread thinks about the solution proposed above. This would add an |
Since this bug is still outstanding and is blocking my upgrade to newer versions of graaphene, I am considering converting all of the affected fields in my project to use graphene string types over the API -- the frontend would need to be passed the set of strings formerly coming from the enumeration. |
|
I figured out a workaround. In this example class UserNode(DjangoObjectType):
gender = graphene.Field(graphene.String, source='gender')
class Meta:
model = User
only_fields = ('id', 'gender') Does anyone know when this bug will be fixed? |
Filtering doesn't work on native enum types either. |
I am on the same boat. Currently, I am using the solution @dspacejs suggested. But it'd be nice to not need to explicitly state CharFields that are blank=True and have choices. |
This seems to be a regression in the upgrade of graphql-core to 2.1 together withj graphene-django to 2.1.0.
Prior to the upgrade, I could create an optional choice field in Django, and could query the value if the value of the choice field was blank.
For example, assume that I have a Django model
MyModel
with an optional choice fieldmy_choices_field
, and a query handler that would accept a query likeWith the updated versions, if the value of
my_choices_field
is blank, this query throws a handled exception like:And the output of the query includes errors when the value of the field is blank:
I imagine the issue is related to the work in graphql-core to related to enum fields
The text was updated successfully, but these errors were encountered: