#34894: Query.change_aliases() has several significant bugs
-------------------------------------+-------------------------------------
Reporter: Aqua | Owner: nobody
Penguin |
Type: Bug | Status: new
Component: Database | Version: 4.2
layer (models, ORM) | Keywords: Query
Severity: Normal | change_aliases
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When using the {{{Query.change_aliases(change_map)}}} method (on an
extended class), some changes are not done and errors occur:
1. the insert order of {{{Query.alias_map}}} is modified, and it is used
by the compiler to compile the FROM parts in the correct order, this can
results in an inconsistant order of the JOIN clauses;
2. even if an entry of {{{Query.alias_map}}} is not in the
{{{change_map}}}, its alias_data may still have to be relabeled if
{{{alias_data.parent_alias}}} is in the {{{change_map}}}, but it is not
done and the generated nested joins that are modified by {{{change_map}}}
have errors in the generated ON clauses;
3. the cached property {{{Query.base_table}}} is not modified if it is in
the {{{change_map}}}, it results in error when compiling the query, the
old alias is searched in {{{Query.alias_refcount}}}, resulting in a
KeyError.
*Solutions:*
1. change the for loop to iterate on the {{{Query.alias_map}}} instead of
the {{{change_map}}}, and rebuild it in the same order with updates;
2. in addition to relabel the entries of {{{Query.alias_map}}} that are in
the {{{change_map}}}, relabel for those whose the
{{{alias_data.parent_alias}}} are in the {{{Query.alias_map}}};
3. change the cached property {{{Query.base_table}}} if it is in the
{{{change_map}}}.
Attached files: patch with fixes and tests
Question: The bugs has been tested on 4.2 and main, I have to do a PR on
all current versions or only on the main branch ?
--
Ticket URL: <https://code.djangoproject.com/ticket/34894>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018b132140b1-6bf9ac01-d712-4393-b630-989d8eb20b31-000000%40eu-central-1.amazonses.com.