#23746: Remedy assertNumQueries dependence on some caches state -----------------------------------+-------------------------------------- Reporter: wrwrwr | Owner: nobody Type: Bug | Status: new Component: Testing framework | Version: master Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -----------------------------------+-------------------------------------- Changes (by wrwrwr):
* needs_better_patch: => 0 * needs_tests: => 0 * needs_docs: => 0 Old description: > The `assertNumQueries` manager / method may return different results > depending on what is in various caches. Consequently, some tests using it > to rely on test ordering, particularly those that count some content type > queries. For instance if you [https://code.djangoproject.com/ticket/23742 > run the suite in reverse] you'll see `test_group_permission_performance` > failing due to `ContentType` being or not being asked about `auth.Group` > in some preceding test ^[#f1 1]^. > > [https://github.com/wrwrwr/django/compare/fix/assert-num-queries-cache- > dependence The proposed solution] resets "query" caches on entering the > manager (with a switch to disable it for actual caching tests). After > introducing the change 10 tests started to fail (`ContentType` cache > tests and some `prefetch_related` tests), 2 specific workarounds were no > longer necessary (#17377, #20432) and a failure from > [https://github.com/django/django/pull/3426 PR 3426] disappeared ^[#f2 > 2]^. > > \\ > > Note to prospective reviewers: Are there any other caches that should be > cleared besides the `ContentType` and `Site`? Related objects caches > maybe? Do the affected `prefetch_related` operations actually require > content type queries? Would it be better to clear all the caches after > every test case to avoid other kinds of dependencies? > > ![1][[=#f1]] What happens in the likewise failing with "--reverse" > `test_user_permission_performance` is a bit intriguing and probably more > involved -- two identical content type queries, savepoint, content type > insertion and a release? > > ![2][[=#f2]] Only tested with Python 3.3 / Postgres, New description: The `assertNumQueries` manager / method may return different results depending on what is in various caches. Consequently, some tests using it rely on test ordering, particularly those that count some content type queries. For instance if you [https://code.djangoproject.com/ticket/23742 run the suite in reverse] you'll see `test_group_permission_performance` failing due to `ContentType` being or not being asked about `auth.Group` in some preceding test ^[#f1 1]^. [https://github.com/wrwrwr/django/compare/fix/assert-num-queries-cache- dependence The proposed solution] resets "query" caches on entering the manager (with a switch to disable it for actual caching tests). After introducing the change 10 tests started to fail (`ContentType` cache tests and some `prefetch_related` tests), 2 specific workarounds were no longer necessary (#17377, #20432) and a failure from [https://github.com/django/django/pull/3426 PR 3426] disappeared ^[#f2 2]^. \\ Note to prospective reviewers: Are there any other caches that should be cleared besides the `ContentType` and `Site`? Related objects caches maybe? Do the affected `prefetch_related` operations actually require content type queries? Would it be better to clear all the caches after every test case to avoid other kinds of dependencies? ![1][[=#f1]] What happens in the likewise failing with "--reverse" `test_user_permission_performance` is a bit intriguing and probably more involved -- two identical content type queries, savepoint, content type insertion and a release? ![2][[=#f2]] Only tested with Python 3.3 / Postgres, -- -- Ticket URL: <https://code.djangoproject.com/ticket/23746#comment:1> 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 post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.03fe8fd5668c1f0c14ec42cda999d6ab%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.