You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OnDeleteType Literal is missing SET DEFAULT and NO ACTION — rejects valid SQL referential actions #1836
The SQL standard defines 5 referential actions for ON DELETE / ON UPDATE:
CASCADE
SET NULL
SET DEFAULT
RESTRICT
NO ACTION
SQLAlchemy's ForeignKey(ondelete=...) accepts any string and its documentation explicitly lists all 5 as valid values.
Impact
NO ACTION is the default behavior in PostgreSQL and most databases. Developers who want to be explicit in their schema (common in migration-driven workflows with Alembic) cannot express this without type errors.
SET DEFAULT is used when a foreign key column has a server_default and the parent row is deleted. This is supported by PostgreSQL, MySQL, and SQLite.
A developer hitting this gets a confusing mypy/pyright error on a perfectly valid schema definition. The only workarounds are casting to Any or dropping down to sa_column.
Fix
OnDeleteType=Literal["CASCADE", "SET NULL", "SET DEFAULT", "RESTRICT", "NO ACTION"]
Activity