dropbox / dropbox/sqlalchemy-stubs

Can not set nullable relationship to None

Open
#166 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
583
Forks
96
PR merge metrics
No merged PRs in 30d

Description

Given the following relationship:

```python
class Game(Base):
__tablename__ = "games"
id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
users = relationship("User", back_populates="game")

class User(Base):
__tablename__ = "users"
xid = Column(BigInteger, primary_key=True, nullable=False)
game_id = Column(Integer, ForeignKey("games.id", ondelete="SET NULL"), nullable=True)
game = relationship("Game", back_populates="users")
```

I'm trying to do the following in the application:

```python
user.game = None
```

This should be fine and it does work as intended in practice, however I get an error from `mypy`:

```
error: Incompatible types in assignment (expression has type "None", variable has type "Game")
```

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.