Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Interfaces are ignored when define Mutation.

未关闭
#1,361 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
api, backend

调研方向

从 graphene/types/mutation.py 中的 init_subclass_with_meta 开始,并复现报告中的 CreatePlan 示例。当定义带有 interfaces 的 mutation 时,即使没有提供显式 output,也能在其输出中保留 interface fields,而不是丢弃它们,即表示修复完成。

由索引模型根据 Issue 内容生成。

描述

🐛 bug

Hello.
First of all, thanks for all graphene developers and contributors.

  • What is the current behavior?
    Interface is ignored when define mutation. This is my code.
class CreatePlan(Mutation):
    class Meta:
        interfaces = (PlanInterface, )

    class Arguments:
        name = String(required=True)
        comment = String(default_value='')
        goal = String(required=True)
        start_date = DateTime(required=True)
        end_date = DateTime(required=True)

    def mutate(parent, info, **kwargs):
        ~~~
# this raises AssertionError:
# CreatePlan fields must be a mapping (dict / OrderedDict)
# with field names as keys or a function which returns such a mapping.
  • What is the expected behavior?
    I think Mutation should includes all interfaces and fields together.

  • Please tell us about your environment:
    Here is my environment.

    • Version: 2.1.9
    • Platform: Mac OS
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
    I think removing just a line can resolve this problem.
    branch v2, graphene/types/mutation.py line 69

    @classmethod
    def __init_subclass_with_meta__(
        cls,
        interfaces=(),
        resolver=None,
        output=None,
        arguments=None,
        _meta=None,
        **options
    ):
        if not _meta:
            _meta = MutationOptions(cls)

        output = output or getattr(cls, "Output", None)
        fields = {}

        for interface in interfaces:
            assert issubclass(interface, Interface), (
                'All interfaces of {} must be a subclass of Interface. Received "{}".'
            ).format(cls.__name__, interface)
            fields.update(interface._meta.fields)

        if not output:
            # If output is defined, we don't need to get the fields
            fields = OrderedDict().  # This ignores interfaces. Remove this.
            for base in reversed(cls.__mro__):
                fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
            output = cls

Also, I found same problem on master branch.

    @classmethod
    def __init_subclass_with_meta__(
        cls,
        interfaces=(),
        resolver=None,
        output=None,
        arguments=None,
        _meta=None,
        **options,
    ):
        if not _meta:
            _meta = MutationOptions(cls)
        output = output or getattr(cls, "Output", None)
        fields = {}

        for interface in interfaces:
            assert issubclass(
                interface, Interface
            ), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
            fields.update(interface._meta.fields)
        if not output:
            # If output is defined, we don't need to get the fields
            fields = {}. # This ignores interfaces. Remove this.
            for base in reversed(cls.__mro__):
                fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
            output = cls
主要语言
Python
星标
8.2k
派生
818
PR 合并指标
30 天内没有已合并 PR

环境准备

我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

graphql-python/graphene 的其他 Issue

查看 graphql-python/graphene 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。