Skip to content

Fix remote_field relation types - #422

Merged
kodiakhq[bot] merged 1 commit into
sbdchd:mainfrom
himanshu748:fix/remote-field-relation-types
Oct 8, 2026
Merged

kodiakhq[bot] merged 1 commit into
sbdchd:mainfrom
himanshu748:fix/remote-field-relation-types

Conversation

@himanshu748

@himanshu748 himanshu748 commented Oct 7, 2026 •

Copy link
Copy Markdown

Fixes #400.

Field.remote_field is a relation object (or None), rather than another Field. The old annotation rejects accesses such as field.remote_field.on_delete, including after narrowing the field to ForeignKey.

  • Type the base attribute as ForeignObjectRel | None.
  • Narrow concrete relation fields to ForeignObjectRel, ManyToOneRel, OneToOneRel, and ManyToManyRel respectively. Keep the base RelatedField optional.
  • Add five regression tests covering optional/scalar fields, concrete relation attributes, nullable fields, and isinstance narrowing.

Validation on Python 3.13.5 / locked Django 5.2.14:

  • All five new tests failed against the original stubs and pass with this change.
  • CI=1 uv run ./s/lint passes: Ruff format/lint, mypy (718 files), Pyright (0 errors/warnings), pytest (43 passed), and ty.
  • Supplemental ty and mypy checks of the new examples pass; git diff --check passes.

@himanshu748
himanshu748 marked this pull request as ready for review October 7, 2026 18:34

@sbdchd sbdchd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@kodiakhq
kodiakhq Bot merged commit 94b9082 into sbdchd:main Oct 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Field.remote_field is typed as Field. Should it be ForeignObjectRel | None?

2 participants