graphql-python / graphql-python/graphene
Graphene v3 ignores mixin/multiple inheritance methods
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 818
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
* **What is the current behavior?**
* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** via
a github repo, https://repl.it or similar.
We use mixins to override `__init__` (and other methods) for certain types. However, Graphene 3 does not seem to handle this python multiple-inheritance correctly. It calls the default `graphene.ObjectType.__init__` instead of the custom `__init__` method defined on the mixin.
A minimal example:
```python
import graphene
class Mixin:
def __init__(self):
print("Calling Mixin.__init__()...")
super().__init__(
value="mixin value"
)
class Thing(Mixin, graphene.ObjectType):
value = graphene.String()
class TestQuery(graphene.ObjectType):
test = graphene.Field(Thing)
resolve_test = lambda parent, info: Thing()
schema = graphene.Schema(query=TestQuery)
print(schema.execute(
"""
{
test {
value
}
}
"""
))
```
In Graphene 2, this works correctly, printing the result `ExecutionResult(data={'test': {'value': 'mixin value'}}, errors=None)` and the statement `Calling Mixin.__init__()...`. However, in Graphene 3, we get the result `ExecutionResult(data={'test': {'value': None}}, errors=None)`, and `Calling Mixin.__init__()...` never prints.
* **What is the expected behavior?**
- `Mixin.__init__` should be called.
- The result of the query should be `ExecutionResult(data={'test': {'value': 'mixin value'}}, errors=None)`
* **What is the motivation / use case for changing the behavior?**
Maintain functionality of graphene 2, enable use of multiple inheritance/mixins
* **Please tell us about your environment:**
- Version: `graphene==3.0b6`
- python `3.6.8`
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
まず、Graphene 3 で最小限の Python 例を実行し、その動作を Graphene 2 の結果と比較します。TestQuery を通じた Thing graphene.ObjectType の構築を追跡し、Mixin.__init__ が呼び出され、クエリが期待される値を返すことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100