I found a solution to workaround this issue.
q1 = AModel.query.with_entities(AModel.share_id.label('ID') , AModel.time.label('time')).filter_by(condition)
q2 = BModel.query.with_entities(BModel.share_id.label('ID') , BModel.time.label('time')).filter_by(condition)
unionSet = union(q1, q2).alias()
result = db.session.query(unionSet).with_entities(unionSet.c.ID, func.max(unionSet.c.time))
.group_by(unionSet.c.document_id).order_by(func.max(unionSet.c.time).desc()).all()
This will return the expacted result from two table with same columns.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…