tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.68k stars 392 forks source link

Tortoise-ORM executed an update statement, but the data in the database didn't change #1688

Open TracyRAN1 opened 3 months ago

TracyRAN1 commented 3 months ago

Under high concurrency, Tortoise-ORM executed an update statement, but the data in the database didn't change, and there were no error messages either. What could be the reason for this?

this is my code: async def update_database_record(model, xs_id: str, updates: dict): async with in_transaction('default'): instance = await model.get(id=xs_id) instance.update_from_dict(updates) await instance.save() logger.info(f"更新数据库记录, model:{model}, xs_id:{xs_id}, updates:{updates}")

this is log: 2024-08-01 19:30:19,056 - DEBUG - tortoise.db_client:197 - 19233 - 139634569598784 - UPDATEDD_APP_ROBOT_PATCH_MESSAGE_RECORDSETORI_CHN=%s,ORI_SYS=%s,ORI_SEQ=%s,POST_TIME=%s,RECEIVE_TIME=%s,RETURN_MSG=%s,SEND_STATUS=%s,CODE=%s,ROBOT_CODE=%s,IDTYPE=%s,USERIDS=%s,TRANS_USERIDS=%s,MSGKEY=%s,MSGPARAM=%s,REQ_DATA=%s,PROCESSQUERYKEY=%s,INVALIDSTAFFIDLIST=%s,FLOWCONTROLLEDSTAFFIDLIST=%s WHEREID=%s: ['LH', 'xebzh', 'test20240801002', datetime.datetime(2024, 8, 1, 19, 30, 18, 357469, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), datetime.datetime(2024, 8, 1, 19, 30, 19, 56569, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), '调用接口成功', 'success', 200, '', 2, "['014401']", '', 'sampleText', "{'content':'并发测试xebzh0801'}", '{"idtype":2,"msgKey":"sampleText","ori_chn":"LH","ori_seq":"test20240801002","ori_sys":"xebzh","userIds":["014401"],"msgParam":"{\'content\':\'并发测试 xebzh0801\'}"}', 'b9RN5kwxEtRhX7HP2KYwVRNkvmUzqMuIctZ37nvbM+Y=', '[]', '[]', '006073f9-4752-409b-aa5b-54e082267899']

arrenanv commented 3 months ago

+1 here. I am also facing this issue