tortoise / tortoise/tortoise-orm
annotate use doubts
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
@hongquan @sinaso @jrmi @allrod5 @charleswhchan
hello,
Describe the bug
When I use foreign key to filter the database table and then use annotate to get the maximum value, I can't work as expected.
To Reproduce
data = await m.WorkInfo.filter(Q(city__name="New York") & Q(position__name="bim")).exclude(Q(minsalary=None) | Q(maxsalary=None)).annotate(max_salary=Max("maxsalary")).values('max_salary')
Expected behavior
I want to get a list containing only one dict, whose dict content is the maximum value of the field "maxsalary" in all filtering results,For example:
[{“max_salary”:135}]
but,What I got was
[{“max_salary”:135},{“max_salary”:13},{“max_salary”:100},......]
Hope to get a reply as soon as possible, thank you!
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 foreign-key filtering and annotate query shown in the issue, then inspect the ORM's annotate and aggregation behavior. Done means determining why multiple dictionaries are returned and establishing behavior that produces the requested single maximum result, with a regression test if the issue is confirmed.
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
- Needs clarification
- Newbie friendliness
- 35/100