tortoise / tortoise/tortoise-orm

Lock in model method `create` (`create` сan be run more than once at the same time)

Open
#985 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Describe the bug
Method create is not locked when it is requested at the same time

To Reproduce
From issues: #792

You can add a asyncio.Lock, in order to ensure that the function will not be started at the same time 2+ times

    @classmethod
    async def create(cls: Type[MODEL], **kwargs: Any) -> MODEL:
        async with self._lock:
            ...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the model classmethod create mentioned in the issue and inspect how concurrent calls are handled. Reproduce two simultaneous create calls, then add coverage showing the method is not started concurrently and verify the existing test suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.