#33319: Query.change_aliases raises an AssertionError
-------------------------------------+-------------------------------------
     Reporter:  Ömer Faruk Abacı     |                    Owner:  Vishal
                                     |  Pandey
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 Ömer,

 > My initial attempt was to use Query.bump_prefix but as you told it threw
 an error.

 The error you encountered is due to `bump_prefix` requiring some
 adjustments. The alias merging algorithm that `Query.combine` uses
 requires that both query share the same initial alias in order to work
 otherwise you'll get a `KeyError`. You'll want to find a way to have
 `bump_prefix` adjust all the aliases but the initial one so it can still
 be used as the merge starting point.

 ---

 Vishal,

 > Here, I am randomly choosing an uppercase letter as the first character
 of alias, this returns different aliases, but a test_case is failing with
 this approach, with the following traceback.

 Choosing a random initial alias will bring more bad than good as not
 relying on `alias_prefix` will cause undeterministic failures across the
 board. There are reasons why the prefix is used and bumped only on
 conflic; it makes reasoning about possible collisions easier.

 > In 2nd approach, I have rotated the alias_prefix in a circular manner
 from T(class variable alias_prefix has value T) to Z, then from A to Z,
 and so on, and it also works on the above-attested code but fails five
 other test cases.

 This approach doesn't account for possible collisions with subquery
 aliases and will eventually collide once you've wrapped up around the 26
 letter of the alphabet instead of using the Cartesian product approach.

 ---

 All of the required logic for preventing `alias_prefix` collisions already
 lives in `bump_prefix`, it's only a matter of adjusting it in order to
 allow it to be used in the alias merging algorithm of `combine`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33319#comment:8>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.9cb463a383b7240db22638d7d9a6333d%40djangoproject.com.

Reply via email to