dropbox / dropbox/sqlalchemy-stubs

Doesn't find column on child class

Open
#96 4 comments 0 reactions 0 assignees View on GitHub
bug priority-normal topic-plugins
Dominant language
Python
Stars
583
Forks
96
PR merge metrics
No merged PRs in 30d

Description

Here is a very simplified reproducer:

```python
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer

Base = declarative_base()

class BaseMixin(Base):
__abstract__ = True

field1 = Column(Integer)

@classmethod
def from_something(cls, something_complicated: int) -> 'BaseMixin':
# Real code tries to figure out which model to use
return MyModel(field1=something_complicated, field2=something_complicated)

class MyModel(BaseMixin):
__tablename__ = 'first-model'

field2 = Column(Integer)
```

With sqlalchemy-stubs from master, I get the following:

```
$ pipenv run mypy model.py
model.py:17: error: Unexpected column "field2" for model "MyModel"
```

But `field2` exists on the model. :confused:

This seems to be due to the order of the code because if I add the following line at the end of the file, then Mypy doesn't report any error:

```python
m = MyModel(field1=1, field2=2)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.