Skip to content
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

to_const doesn't support unicode #1079

Closed
henrythor opened this issue Oct 4, 2019 · 2 comments · Fixed by #1080
Closed

to_const doesn't support unicode #1079

henrythor opened this issue Oct 4, 2019 · 2 comments · Fixed by #1080

Comments

@henrythor
Copy link
Contributor

henrythor commented Oct 4, 2019

Let's say I have a model in Django with a field that has choices. Only, because I'm Icelandic, those choices might be in Icelandic and contain utf-8 characters. Generating an enum from my model will fail.

F.ex.:

class School(models.Model):
    MUNICIPALITIES = (
        ('Hafnarfjarðarkaupstaður', 'Hafnarfjarðarkaupstaður'),
        ('Reykjanesbær', 'Reykjanesbær'),
        ('Garðabær', 'Garðabær'),
        ...
    )
    name = models.CharField(max_length=128)
    municipality = models.CharField(max_length=32, blank=True, null=True, choices=MUNICIPALITIES)

I then try to create a Query object:

class SchoolNode(DjangoObjectType):
    @classmethod
    class Meta:
        model = School
        filter_fields = [
            'id',
            'name',
        ]
        exclude_fields = [
        ]
        interfaces = (relay.Node,)


class Query(object):
    school = relay.Node.Field(SchoolNode)
    all_schools = DjangoFilterConnectionField(SchoolNode)

This will then fail in graphql.utils.assert_valid_name.assert_valid_name at schema evaluation since to_const doesn't handle converting unicode characters to ascii:
Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "A_HAFNARFJARÐARKAUPSTAÐUR" does not.

I really doubt I'm the only one running into this. Most people just handle this stuff differently I suppose? Manually switch out code, or use an actual Enum() in the choices?

My proposed solution is to use the unidecode package, specifically designed for this. I'll throw together a PR.

@stale
Copy link

stale bot commented Jan 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 2, 2020
@stale stale bot closed this as completed Jan 16, 2020
@ekampf
Copy link
Contributor

ekampf commented Feb 8, 2020

FYI fixed on #1080

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 a pull request may close this issue.

2 participants