tortoise / tortoise/tortoise-orm

filter on foreign key attribute and update raises OperationalError in database

Open
#1,226 0 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

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:

1401-05-30_14h03_22

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.