python - 'input' 是 print() 的无效关键字参数
问题描述
我正在使用 graphene-django 作为 api。我正在尝试创建一个突变来创建一个具有公司外键的品牌。当我变异时,我收到以下错误“'input' is an invalid keyword argument for print()”。我不知道为什么会抛出这个错误。
这是我的突变
class BrandInput(graphene.InputObjectType):
company = graphene.List(CompanyInput)
name = graphene.String()
website = graphene.String()
description = graphene.String()
country = graphene.String()
city = graphene.String()
address = graphene.String()
class CreateBrand(graphene.Mutation):
class Arguments:
input = BrandInput(description="These fields are required", required=True)
class Meta:
description = "Create Brand Mutation"
errors = graphene.String()
brand = graphene.Field(BrandNode)
@staticmethod
def mutate(root, info, **args):
print('args', args, **args)
if not info.context.user.is_authenticated:
return CreateBrand(errors=json.dumps('Please Login to list your brand'))
try:
company = models.Company.objects.get(slug=args.get('input')['company'])
if company:
brand = models.Brand.objects.create(
company=company,
name=args.get('input')['name'],
slug = args.get('input')['slug'],
website = args.get('input')['website'],
description = args.get('input')['description'],
country = args.get('input')['country'],
city = args.get('input')['city'],
address = args.get('input')['address'],
)
return CreateBrand(brand=brand, errors=null)
except models.Company.DoesNotExist:
return CreateBrand(errors=json.dumps('Company should be required'))
我对此感到怀疑,company = graphene.List(CompanyInput)
因此我将其更改为company = graphene.String()
并提供了公司的名称,以便在更改品牌时可以找到公司实例。但我得到同样的错误。
突变的查询是
mutation {
createBrand(input: {company: "wafty-company", name: "Wafty Brand", website: "www.wafty.com", description: "Wafty brand description", country: "Nepal", city: "Kathmandu", address: "Baneshwor", pinCode: "44600", operationDate: "2018-10-02 15:32:37", franchisingDate: "2018-10-02 15:32:37", numberOfFranchises: "0-10", numberOfOutlets: "0-10"}) {
errors
brand {
name
slug
website
}
}
}
解决方案
当您尝试将这样的参数传递**args
给print()
此参数时,该参数将被解压缩为关键字参数,这将引发错误,因为print()
不期望mutate()
方法具有这样的参数。所以你需要删除**args
:
print('args', args)
推荐阅读
- angular - 如何实现角度材料互斥的可检查菜单项?
- matlab - Matlab 估计AssetMoments 示例错误
- javascript - 如何在 JSP-Servlet 中执行延迟加载?
- android - 开发时如何测试cordova插件?
- c++ - C++ try catch 不适用于数组越界
- javascript - Chart.js 如何删除图表上的最终标签
- regex - Lookbehind 难题或团体?
- scala - 运行 spark-submit 的问题:java.lang.NoSuchMethodError: com.couchbase.spark.streaming.Mutation.key()
- javascript - 多个过滤器一起工作。将多个过滤器类型匹配在一起
- python - 如何使用嵌套序列化程序我收到属性错误