graphql-python / graphql-python/graphene
Enum.from_enum() fails with Django IntegerChoices
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 818
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Current Behavior
I am working in a Django Python codebase that has a GraphQL schema. A lot of TextChoices are used in our GraphQL schema and, to properly represent these we use the provided graphene.Enum.from_enum() function.
This same approach doesn't seem to work with Django's IntegerChoices. It seems when graphene generates a GrapheneEnumType, the values are created with the IntegerChoices member names. This makes it so the IntegerChoices value cannot be represented with the generated GrapheneEnumType.
This results in an error like the following:
"Enum 'Status' cannot represent value: 2"
Expected Behavior
A value from a Django IntegerChoices object is usable to get the appropriate GrapheneEnumType value name.
motivation
To allow for graphene.Enum.from_enum() to be usable by Django's IntegerChoices class.
Environment
- Graphene Version: 3.3
- Graphene Django Version: 3.2.0
- Graphene Version: 3.3
- Django Version: 4.1.12
- Python Version: 3.10
Code Example
class Status(models.IntegerChoices):
COMPLETED = 1, "Completed"
IN_PROGRESS = 2, "In progress"
ERRORED = 9, "Errored"
StatusChoices = graphene.Enum.from_enum(Status)
class Process(graphene.ObjectType):
reference = graphene.String(description="The process reference.")
status = graphene.Field(
StatusChoices,
description="Current process status.",
)
This results in an error like the following:
"Enum 'Status' cannot represent value: 2"
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
graphene.Enum.from_enum() と生成された GrapheneEnumType の動作から始め、提供されている Django IntegerChoices の例を使って失敗を再現します。TextChoices と IntegerChoices の処理を比較します。1、2、9 などの値を、報告されたエラーなしに生成された Graphene enum で表現できれば、作業は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- django, graphql, python
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100