tortoise / tortoise/tortoise-orm
filter on foreign key attribute and update raises OperationalError in database
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
class Contact(Model):
phone_no = fields.CharField(max_length=255)
class ChildContact(Model):
contact = fields.ForeignKeyField('models.Contact', related_name='child_contacts')
await ChildContact.filter(child_id=body.child_id, contact__phone_no=body.contact_phone_no).update(is_deleted=True)
running the generated sql in terminal generates this log in postgres:

UPDATE "childcontact"
SET "is_deleted"=$1
FROM "childcontact" "childcontact_"
LEFT OUTER JOIN "contact" "childcontact__contact" ON "childcontact__contact"."id"="childcontact"."contact_id"
WHERE "childcontact"."child_id"='b99f16d3-2a7c-4e55-bca6-a4b8c86edff3' AND "childcontact__contact"."phone_no"='09121111111';
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
Start by reproducing the shown ChildContact.filter(...).update(...) query against PostgreSQL and inspect the generated UPDATE SQL. Trace the ORM's relation-filter update path; done means the foreign-key attribute filter updates the matching rows without PostgreSQL OperationalError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100