AssertionError:在架构中找到了具有相同名称的不同类型

时间:2019-04-29 11:16:31

标签: python graphql graphene-python graphene-sqlalchemy

我有两个类:模型中的Products和SalableProducts(SalableProducts继承自Products,因此它具有数据库的每个字段)。这是我的下方模式

我尝试添加“ exclude_fields”属性,但这没用

Product_schema.py:

kong_1             | 172.21.0.1 - - [29/Apr/2019:10:36:58 +0000] "POST /apis HTTP/1.1" 404 23 "-" "PostmanRuntime/7.6.0"
kong_1             | 172.21.0.1 - - [29/Apr/2019:10:47:30 +0000] "POST /apis HTTP/1.1" 404 23 "-" "PostmanRuntime/7.6.0"

Salable_product_schema.py:

class Product(SQLAlchemyObjectType):
 class Meta:
  model = ProductModel
  interfaces = (relay.Node, )

class ProductConnections(relay.Connection):
 class Meta:
  node = Product

Schema.py:

class SalableProduct(SQLAlchemyObjectType):
 class Meta:
  model = SalableProductModel
  interfaces = (relay.Node, )

class SalableProductConnections(relay.Connection):
 class Meta:
  node = SalableProduct

结果是此错误:

  

AssertionError:在架构中找到了具有相同名称的不同类型:product_status,product_status。

(product_status是两个类通过继承共享的属性)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。在我的特定情况下,问题是使用backref时SQLAlchemy的内部工作方式冲突。我会检查模型,看看是否是这种情况。

以下article具有一些相关信息。在我的特殊情况下,我尝试了建议的方法并重命名了其中一个连接:

techniques = SQLAlchemyConnectionField(TechniqueConnection)
belts = SQLAlchemyConnectionField(BeltConnection)
belt_techniques = SQLAlchemyConnectionField(BeltTechniqueConnections)

我在BeltTechniqueConnection后面附加了一个“ s”。相关的模型与技术和皮带有很多关系。