Skip to content

fix: infer required SQLAlchemy relationship types - #8046

Open
harsh21234i wants to merge 1 commit into
reflex-dev:mainfrom
harsh21234i:fix/8044-sqlalchemy-relationship-nullability
Open

harsh21234i wants to merge 1 commit into
reflex-dev:mainfrom
harsh21234i:fix/8044-sqlalchemy-relationship-nullability

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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.

Verification

  • Reproduced the reported optional type on main.
  • Ran the relationship inference and Var tests on Python 3.11 and 3.14.
  • Verified a required relationship backed by a composite foreign key.

Closes #8044.

View guided diff

@harsh21234i
harsh21234i requested a review from a team as a code owner November 28, 2026 08:07
@FarhanAliRaza FarhanAliRaza added the bug Something isn't working label Nov 28, 2026 — with ChatGPT Codex Connector
@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were established.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were established.

Summary

Infers required SQLAlchemy scalar relationships from their Mapped annotation and a complete, non-nullable foreign key.

  • State Vars now treat guaranteed SQLAlchemy relationships as required.

Reviews (1) · Last reviewed commit: "fix: infer required SQLAlchemy relations..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

View guided diff | Re-trigger cubic

@codspeed

codspeed Bot commented Nov 28, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 16 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 146 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing harsh21234i:fix/8044-sqlalchemy-relationship-nullability (d8aafef) with main (6f5c39c)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-nullable SQLAlchemy relationships are typed as optional

2 participants