Repository navigation
fix: derive table aliases from relation paths - #1842
Conversation
…parsing, prefetch and values
…ate order alias branch
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will improve performance by 23.64%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ |
test_sum[500] |
8 ms | 6 ms | +34.49% |
| ⚡ |
test_avg[250] |
8.1 ms | 7.1 ms | +13.67% |
| 🆕 |
test_duplicate_relation_paths[100] |
N/A | 156.8 ms | N/A |
| 🆕 |
test_duplicate_relation_paths[200] |
N/A | 299 ms | N/A |
| 🆕 |
test_duplicate_relation_paths[50] |
N/A | 89.7 ms | N/A |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix/path-based-table-aliases (ef52ba6) with master (1405d58)
…lumn alias Co-authored-by: moneebullah25 <moneebullah25@gmail.com>
Table aliases are a pure function of the relation path, so the values() column map no longer needs a stateful class. It is built once per call as a dict of table alias to label and allowed columns, and through tables are registered explicitly instead of being detected by a substring check.
AliasManager only held a static column builder and a cache of aliased tables, shared as one global instance on every OrmarConfig. Replace it with prefixed_columns and a cached prefixed_table function, drop OrmarConfig.alias_manager and rename the module to ormar/relations/aliases.py.
Table aliases are now derived from the relation path (
alias_for("aseller__city")) instead of a global per-relation registry with "complex" aliases for duplicated paths. This fixes filters,exclude(),order_by(),fields()/exclude_fields(),values()andprefetch_related()on relation paths that end in the same relation, regardless of call order, and removes the in-place alias switching that let a derived queryset corrupt its source. Duplicate many-to-many paths that failed with "Ambiguous column name" now work, andselect_related()on a through model raises a clear error.Also fixes chained
exclude()(based on #1826) and aselect_related()crash when a column alias on the related model equals the relation name (based on #1829), both by @moneebullah25.Closes #1816
Closes #1827