tortoise / tortoise/tortoise-orm

Auto discover models recursively

Open
#504 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Problem

For now, we need to specify explicitly from which modules Tortoise finds models, but not submodules, recursively.

In the example below, Tortoise loads models from models module, but not models.users or models.users.customers.

tortoise_config = {
    "connections": {"default": DATABASE_URI},
    "apps": {
        "models": {
            "models": ["models", "aerich.models"]
        }
    },
}
Proposed Solutions
  1. Support "models": ["models.*", "aerich.models"] syntax.
  2. Add another flag to discover models recursively.

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 at the configuration handling for the apps.models.models entries shown in the example, and trace how a module is currently discovered. Resolve whether wildcard syntax or a recursive-discovery flag is the intended API, then define behavior for nested modules such as models.users.customers. Done means the selected API discovers models recursively while preserving explicit entries such as aerich.models.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.