#17758: Do not depend on dict order in test suite
---------------------------------+------------------------------------
     Reporter:  lrekucki         |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  Core (Other)     |                  Version:  1.3
     Severity:  Release blocker  |               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 lrekucki):

 OK, I found 2 major bugs so far:

 1) {{{django.test.simple.dependency_order()}}}

 There are two problems here:

 a) The result of this functions depends on the order of aliases for given
 DB signature (which in turn depends on the order in settings.DATABASES
 dict) - i.e. if you have a DB with aliases {{{["A", "B"]}}} and "A"
 depends on "B" then it will raise an error. If the alias list is ["B",
 "A"] it will pass (I think it should always fail, right?).

 b) The way setup_databases() in the runner treat databases with no
 {{{NAME}}} - they get the same signature. There's a special case later to
 fix this, but it messes up dependency_order(). In particular, the Django
 test suite has two DBs: "default" and "other". If they're assigned the
 same test_signature, they're treated as aliases (which isn't correct). As
 documented, the "other" database has an implicit dependency on "default"
 because we gave no explicit {{{TEST_DEPENDENCIES}}}. And that's how we
 arrive at a).

 So right now, you have about 50% chance of even running the test suite ;)
 I don't have a patch for a general case yet. ATM, I modified the backend
 code to return NaN instead of empty string for databases with no
 {{{NAME}}}, which prevents them from being aliases. This should also be
 the case for SQLite databases where {{{NAME == ":memory:"}}}. And of
 course, {{{dependency_order()}}} needs fixing.

 2) An ORM bug

 {{{
 FAIL: test_tickets_8921_9188 (regressiontests.queries.tests.Queries6Tests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 "/home/lrekucki/django/django_lqc/tests/regressiontests/queries/tests.py",
 line 1443, in test_tickets_8921_9188
     ['<Tag: t1>', '<Tag: t4>', '<Tag: t5>']
   File "/home/lrekucki/django/django_lqc/django/test/testcases.py", line
 774, in assertQuerysetEqual
     return self.assertEqual(map(transform, qs), values)
 AssertionError: Lists differ: ['<Tag: t4>', '<Tag: t5>'] != ['<Tag: t1>',
 '<Tag: t4>', '<T...
 }}}

 I tracked the problem down to {{{QuerySet.alias_refcount}}} and
 {{{QuerySet.split_exclude}}} which assumes a specific order on the former.
 The order can be preserved using SortedDict, but there are a few places
 that relabel aliases and ruin the order, like
 {{{QuerySet.change_aliases()}}}. (this iterates through {{{change_map}}}
 argument which is a dictionary, so the new aliases are inserted in random
 order). I fixed this, by using {{{change_map = SortedDict()}}} in
 {{{QuerySet.split_exclude}}}. This should probably apply to all
 {{{change_map}}}s when working with aliases.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17758#comment:2>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to