tortoise / tortoise/tortoise-orm

autocomplate for fields(column)

Open
#1,349 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

Is your feature request related to a problem? Please describe.
Hi, tortoise orm is very interesting with its async , but after many hours I still could not figure out how to make the pylint autocomplation work in the model.

Example

from tortoise.models import Model
from tortoise import fields

class Tournament(Model):
    id = fields.IntField(pk=True)
    name = fields.TextField()

    def __str__(self):
        return self.name

tournament = Tournament(wrongname = 'some string')

In VSCode and pycharm there will be no error prompts

Describe the solution you'd like
sqlalchemy 2 has MappedAsDataclass, which allows you to use all the power of autocompleteness.

The problem with sqlalchemy v2 right now is that almost all the examples on the web are written for sqlalchemy v1.x or without async. This also looks like an advantage for tortoise-orm and a growth point.

from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import MappedAsDataclass

class Base(MappedAsDataclass,
           DeclarativeBase
           ):
    pass


class Tournament(Base):
    __tablename__ = "tournament"
    __table_args__ = {"schema": SCHEMA}

    id: Mapped[int] = mapped_column(init = False, primary_key=True)
    name : Mapped[str]
    def __repr__(self) -> str:
        return f"Tournament(id={self.id!r}, prompt={self.name !r})"

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 reviewing Tortoise ORM model and field declarations, then compare the SQLAlchemy 2 MappedAsDataclass example in the issue. The issue does not name files, tests, or a specific implementation path; done would require a defined approach that makes invalid model constructor fields visible in VSCode and PyCharm.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
database, developer-experience
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.