我正在嘗試使用瓶框架編寫REST api。我的基類CRUD有兩種方法。 基本查詢執行查詢,get_values方法遍歷結果並返回數據。但我得到的對象不可迭代錯誤。Bottle框架SqlAlchemy類型錯誤:對象不可迭代
class InfluencerCrud(CrudObject):
def base_query(self, db_session, request_params):
return db_session.query(Groups, GroupLeaders, Users) \
.filter(GroupLeaders.id == Groups.group_leaders_id) \
.filter(Users.id == GroupLeaders.users_id)
def get_values(self, db_session, request_params, raw_result):
logging.error(raw_result)
for group, group_leader, user in raw_result:
data = as_dict(group, include_columns = ['clicks_estimated', 'completeness', 'cpc', 'created_at',
'description', 'guid','languages_id', 'name', 'registration_status',
'size', 'url', 'verticals_id'])
data['addresses_id'] = user.addresses_id
data['user'] = as_dict(user, include_columns = ["addresses_id", "created_at", "education_id", "email",
"email_verified_at", "gender", "income_id", "marital_status_id",
"name_first", "name_last", "phone", "status", "updated_at", "worK_status_id"])
data['user']['race_id'] = []
c = session.query(UserHasRace.race_id).filter(UserHasRace.user_id == user.id)
for r, in c:
data['user']['race_id'].append(r)
data['user']['children'] = []
c = session.query(UserChildren).filter(UserChildren.user_id == user.id)
for r in c:
data['user']['children'].append(get_dict_obj(r))
picurl = None
up = session.query(UserPicture).filter(UserPicture.id == user.pictures_id).first()
if up != None and up.file_name != None:
i = up.file_name.rfind('/')
picurl = linqia.system.config.avatars.s3_url + 'user_pictures/' + up.file_name[i + 1:]
data['user']['picture_url'] = picurl
return data
以下是錯誤
File "/home/linqia-api-internal/current/api-internal/source/influencers/influencer.py", line 42, in get_values [Tue Feb 14 20:41:10 2017] [error] [client ::1] for group, group_leader, user in raw_result: [Tue Feb 14 20:41:10 2017] [error] [client ::1] TypeError: 'Groups' object is not iterable
當我試圖打印的原始數據,我越來越引用到所有的三個對象。我只是沒有得到迭代他們。
任何幫助,將不勝感激,謝謝