graphql-python / graphql-python/graphene

Graphene v3 ignores mixin/multiple inheritance methods

Đang mở
#1,292 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
🐛 bug
Ngôn ngữ chính
Python
Star
8.2k
Fork
818
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

* **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`

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu bằng cách chạy ví dụ Python tối thiểu với Graphene 3 và so sánh hành vi của nó với kết quả của Graphene 2. Theo dõi quá trình xây dựng Thing graphene.ObjectType thông qua TestQuery và xác minh rằng Mixin.__init__ được gọi và truy vấn trả về giá trị mong đợi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.