tortoise / tortoise/tortoise-orm

Option to ensure only one object per database row

Open
#791 2 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

Is there a way to configure Tortoise so that for all queries returning a Model object for a given database table row, there are never separate instances of that Model object?

At the moment, if 2 or more tasks perform queries on a table, they will often get separate Model objects referring to the same database row. This of course is a massive integrity issue.

In my project, confining record updates to occurring within transaction blocks is not an option, because I'm ending up with deadlocks. I think there may be cases within Tortoise itself where locks are not getting released.

What would simplify this is some kind of option that ensures that for any given database row, there can only exist one Model object.

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

The issue names no files, tests, or entry points. Start by tracing how Tortoise creates Model instances for repeated queries and how its transaction and lock handling behave; done would require a decided, tested approach that guarantees the requested per-row instance identity without leaving locks unreleased.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.