sqlalchemy-stubs icon indicating copy to clipboard operation
sqlalchemy-stubs copied to clipboard

Can't use Column with automatic data type and ForeignKey

Open jace opened this issue 3 years ago • 0 comments

SQLAlchemy supports automatic type detection with foreign key columns:

class MyModel(Model):
    my_column = Column(None, ForeignKey('other_table.other_column'))

However this call variant is not present in the stubs. Mypy says:

error: No overload variant of "Column" matches argument types "None", "ForeignKey"  [call-overload]
note: Possible overload variants:
note:     def [_T] __init__(self, name: str, type_: Type[TypeEngine[_T]], *args: Any, autoincrement: Union[bool, str] = ..., default: Any = ..., doc: str = ..., key: str = ..., index: bool = ..., info: Mapping[str, Any] = ..., nullable: bool = ..., onupdate: Any = ..., primary_key: bool = ..., server_default: Any = ..., server_onupdate: Union[FetchedValue, FunctionElement[Any]] = ..., quote: Optional[bool] = ..., unique: bool = ..., system: bool = ..., comment: str = ...) -> Column[_T]
note:     def [_T] __init__(self, name: str, type_: TypeEngine[_T], *args: Any, autoincrement: Union[bool, str] = ..., default: Any = ..., doc: str = ..., key: str = ..., index: bool = ..., info: Mapping[str, Any] = ..., nullable: bool = ..., onupdate: Any = ..., primary_key: bool = ..., server_default: Any = ..., server_onupdate: Union[FetchedValue, FunctionElement[Any]] = ..., quote: Optional[bool] = ..., unique: bool = ..., system: bool = ..., comment: str = ...) -> Column[_T]
note:     <4 more similar overloads not shown, out of 6 total overloads>

This issue is distinct from #67 (Can't use ForeignKey in Column).

jace avatar Jan 17 '21 13:01 jace