fix: infer required SQLAlchemy relationship types

Closed
HA
1d ago
+192-11

Summary

  • Infer a scalar SQLAlchemy relationship as required when its Mapped annotation 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 undefined in 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.