fix: infer required SQLAlchemy relationship types
Closed
HA
18h ago+192+192+012345678901234567890123456789-11-11-01234567890123456789
Summary
- Infer a scalar SQLAlchemy relationship as required when its
Mappedannotation requires a value and its join follows a complete non-nullable foreign key. - Preserve optional types for nullable keys, explicitly optional annotations, inverse scalar relationships, and joins that can filter out the related row.
- Verify the State Var type and the generated expression for nested relationship access.
- Document in the database relationships page that the Var type follows the schema: a relationship the query did not load is still
undefinedin the browser.
Verification
- Reproduced the reported optional type on
main. - Ran the relationship inference and Var tests on Python 3.11 and 3.14.
- Tested a required relationship backed by a composite foreign key, a partly nullable composite key, and an annotation that does not resolve.
Closes #8044.