tortoise / tortoise/tortoise-orm

source_field break __iter__

Open
#1,115 2 comments 0 reactions 0 assignees View on GitHub

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
When a field specifies source_field, Model.__iter__() no longer works.

To Reproduce

from tortoise import Model
from tortoise.fields import BigIntField
class SampleModel(Model):
    id_ = BigIntField(pk=True, source_field='id')
    
a = SampleModel(id_=1)
[i for i in a]

Expected behavior
This iteration sho

Additional context
Python 3.10.4
tortoise-orm==0.19.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example with a model field using source_field and inspect Model.iter together with the field-name handling. Confirm the expected iteration behavior from the issue context, then add coverage for the reproduction and verify that iteration works without breaking normal fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.