tortoise / tortoise/tortoise-orm
Tortoise-ORM executed an update statement, but the data in the database didn't change
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
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 - UPDATE DD_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 WHERE ID=%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']
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided update_database_record flow and logged UPDATE statement; inspect how model.get, update_from_dict, and save behave inside in_transaction under concurrency. Reproduce the unchanged-data case and determine whether the transaction or update path reports affected rows or errors. Done means identifying the cause and documenting or fixing it with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100