tortoise / tortoise/tortoise-orm
select_related on one2one field returns unfilled objects
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
A clear and concise description of what the bug is.
the example models look like this
class B(Model):
id = fields.UUIDField(pk=True)
class A(Model):
the_b = fields.OneToOneField(
"models.B", related_name="the_a", on_delete=fields.SET_NULL, null=True
)
then i get it like:
a = A.all().select_related('the_b').get(id=<some_uuid>)
and got:
a.the_b is not None while a.the_b_id is None
but for some reason
a = A.all().prefetch_related('the_b')
a.the_b is None
is this intended behaviour and do you have any plans to fix it ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the A/B models and compare select_related('the_b') with prefetch_related('the_b'). Trace the relation-loading entry points for both paths and verify how the related object and the the_b_id value are populated. Done means the two loading strategies consistently reflect the relationship state, with regression coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100