tortoise / tortoise/tortoise-orm
Multiple many to many relationships between the same tables will use the same through table silently
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
Two many to many fields to the same related object will use the same through table.
To Reproduce
class User(Model):
username = fields.TextField()
class MergeRequest(Model):
assignees = fields.ManyToManyField(
"User", related_name="merge_requests_assignee", null=True
)
reviewers = fields.ManyToManyField(
"User", related_name="merge_requests_reviewer", null=True
)
Expected behavior
I would expect an error demanding through to be defined or the field name to be included in the through table name.
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 running the supplied User and MergeRequest model reproduction and verify whether assignees and reviewers use the same through table. Determine which expected behavior is intended—requiring an explicit through value or including the field name in the generated table name—and consider the corresponding regression coverage. Done means the collision is no longer silent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100