Python SQLAlchemy递归CTE查询不';是否返回非列成员?

Python SQLAlchemy递归CTE查询不';是否返回非列成员?,python,sqlalchemy,common-table-expression,Python,Sqlalchemy,Common Table Expression,我有以下课程: class Catalog(Base): __tablename__ = 'catalog' id = Column(String, primary_key=True) parentid = Column(String, ForeignKey('catalog.id')) name = Column(String) parent = relationship("Catalog", remote_side=[id])] @prope

我有以下课程:

class Catalog(Base):
    __tablename__ = 'catalog'
    id = Column(String, primary_key=True)
    parentid = Column(String, ForeignKey('catalog.id'))
    name = Column(String)
    parent = relationship("Catalog", remote_side=[id])]

    @property
    def operative_name_stamp(self):
        node = self
        while not node.name and node.parent:
            node = node.parent
        return node.name
如果我执行一些基于CTE的递归查询:

hierarchy = session.query(
        Catalog, literal(0).label('level'))\
        .filter(Catalog.parentid == null())\
        .cte(name="hierarchy", recursive=True)

parent = aliased(hierarchy, name="p")
children = aliased(Catalog, name="c")
hierarchy = hierarchy.union_all(
            session.query(
                children,
                (parent.c.level + 1).label("level"))
            .filter(children.parentid == parent.c.id))

result = session.query(Catalog, hierarchy.c.level)\
        .select_entity_from(hierarchy).all()
这只会给我一个带有列成员的元组层次结构,但缺少非列成员--
操作名\u stamp


有没有办法将这些成员包括在结果中?

这个问题可以通过使用字典而不是列表作为返回结果来轻松解决。这样,您就可以通过主键“查找”您喜欢的任何内容。这让我想起了看似复杂的生活

我不理解CTE,我的输入是一个实体类,但我的输出变成了一个元组。