Skip to content

missing-argument false positive for SQLModel Field(primary_key=True) #2887

@Duckling92

Description

@Duckling92

Summary

When a SQLModel table class has a field with Field(primary_key=True), SQLModel makes that field optional in __init__ (the database auto-generates it).
ty incorrectly reports missing-argument because it doesn't recognize that primary_key=True changes the field's optionality.

Minimal repro

from sqlmodel import Field, SQLModel


class Item(SQLModel, table=True):
    id: int = Field(primary_key=True)
    name: str = Field(default="test")


# This is valid — SQLModel makes `id` optional because it's a primary key.
# At runtime, the database auto-generates the id.
item = Item()

Then

ty check .

Expected

No error. Item() is valid because primary_key=True makes id optional in the constructor (both mypy and pyright pass, and it works at runtime).

Actual

error[missing-argument]: No argument provided for required parameter `id`

Environment

  • ty 0.0.18
  • SQLModel 0.0.27
  • Python 3.13

Version

ty 0.0.18

Metadata

Metadata

Assignees

No one assigned

    Labels

    libraryDedicated support for popular third-party libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions