tortoise / tortoise/tortoise-orm
Identifier Length Maximums in Values/Only Query
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 selecting relations via .values or .only, the fields are given full relation names. These names become quite long. Oracle is moving to longer names, but even still the length can balloon if there are two or more relations deep, and I'm stuck on a version that only supports 30 character long identifiers.
To Reproduce
results = await Mask.all().values('name', 'tapeoutprojectname__tapeoutprojectname')
SELECT
tesreport.tesexecplan.masklayername name,
tesexecplan__tapeoutprojectname.tapeoutprojectname tapeoutprojectname__tapeoutprojectname
FROM
tesreport.tesexecplan
LEFT OUTER JOIN tesreport.testapeoutproject tesexecplan__tapeoutprojectname ON tesexecplan__tapeoutprojectname.objref=tesexecplan.tapeoutprojectobjref
Expected behavior
SQLAlchemy solves this by giving the fields numbered aliases; however, any kind of aliasing would work.
Additionally, it may be nice to be able to set an identifier length such that none of the fields are aliased unless they meet that length. I assume slapping these aliases into a dict before running the query would be pretty straight forward.
Additional context
12c release 12.2 ups the identifier length to 128. Even if I had this room, I am pretty sure I could reach that limit in a few relations.
https://oracle-base.com/articles/12c/long-identifiers-12cr2
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 tracing how .values and .only build selected relation fields and the generated SQL shown in the report. Check how aliases could be assigned while preserving the requested result keys, and consider the requested identifier-length limit. Done means deeply related selected fields produce SQL identifiers within the database limit without changing returned values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100