SqlAlchemy无法在未映射的子类上设置属性

2024-05-14 23:59:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我的继承层次结构如下所示:

Fruits
   Apples (has type='apple')
      GrannySmith (has type='grannysmith')
      Rotten (does not have a mapping defined)

当实例化Rotten类型的东西并试图在apple中设置一个具有列的属性时,我看到以下错误:

File ".../sqlalchemy/orm/attributes.py", line 228, in __set__
    self.impl.set(instance_state(instance),
AttributeError: 'NoneType' object has no attribute 'set'

我不知道为什么会这样,但是如果我将Rotten映射到一个类型,我就看不到这个问题了。知道我为什么要画一个类吗

我希望能够对父类可能恰好映射到表的类进行子类化,但不要求子类具有任何数据库交互

有关在最后一行显示异常的示例,请参见gist


Tags: instance类型apple层次结构havetypenothas

热门问题