【问题标题】:AssertionError: Found different types with the same name in the schemaAssertionError:在架构中找到具有相同名称的不同类型
【发布时间】:2019-09-18 00:15:30
【问题描述】:

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

我尝试包含“exclude_fields”属性,但没有成功

Product_schema.py:

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

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

Salable_product_schema.py:

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

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

Schema.py:

class Query(graphene.ObjectType):
 node = relay.Node.Field()
 all_products = SQLAlchemyConnectionField(ProductConnections)
 all_salable_products = 
  SQLAlchemyConnectionField(SalableProductConnections)

结果是这个错误:

AssertionError:在架构中发现具有相同名称的不同类型:product_status、product_status。

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

【问题讨论】:

    标签: python graphql graphene-python graphene-sqlalchemy


    【解决方案1】:

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

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

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

    我在 BeltTechniqueConnection 上附加了一个“s”。相关模型与技术和腰带有多对多的关系。

    【讨论】:

    • 我也有这个错误。我的 models.py 中有一个字段,我将其命名为 typetype 似乎是保留字
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多