Skip to content

Version 1.4 seems to break when django.templates.backends has not been initialized #32

Description

@PamelaM

This is clearly a bug caused by my recent PR.

  Coverage.py warning: Disabling plugin 'django_coverage_plugin.DjangoTemplatePlugin' due to an exception:
 Traceback (most recent call last):
   File "/home/teamcity/.virtualenvs/addgene1.8/local/lib/python2.7/site-packages/coverage/control.py", line 476, in _should_trace_internal
     file_tracer = plugin.file_tracer(canonical)
   File "/home/teamcity/.virtualenvs/addgene1.8/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.py", line 158, in file_tracer
     self.debug_checked = check_debug()
   File "/home/teamcity/.virtualenvs/addgene1.8/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.py", line 56, in check_debug
     if not hasattr(django.template.backends, "django"):

I'll work though a fix PR in the next two days.

Because of the chicken-and-egg issues of starting, I think the need for a test_project that can be used for full integration testing via subprocess calls is even more vital. There are too many "shenanigans" involved with getting coverage/django startup initialization order reversed and re-run during the current test process.

Activity

  1. PamelaM commented on Jan 19, 2017

    @PamelaM
    CollaboratorAuthor

    I can only reproduce it in one case where we're not using a management command, so this doesn't look like a complete show-stopper. Still looking at it

  2. ambivalentno commented on Jan 19, 2017

    @ambivalentno

    I observe such behavior even if running with coverage run manage.py test (Django 1.6 project migrating to 1.8)

  3. garyayo commented on Jan 25, 2017

    @garyayo

    I just wanted to add that we've just recently started to experience this issue...

    (backend) [17:43:43] gary:backend git:(dev*) $ coverage run ./manage.py test -v 2
    Coverage.py warning: Disabling plugin 'django_coverage_plugin.DjangoTemplatePlugin' due to an exception:
    Traceback (most recent call last):
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/coverage/control.py", line 476, in _should_trace_internal
        file_tracer = plugin.file_tracer(canonical)
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.py", line 158, in file_tracer
        self.debug_checked = check_debug()
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.py", line 56, in check_debug
        if not hasattr(django.template.backends, "django"):
    AttributeError: 'module' object has no attribute 'backends'
    

    We're currently running:

    coverage==4.3.4
    django-coverage-plugin==1.4
    Django==1.9
    

    Any idea how we can resolve this issue and move forward?

    Thanks

  4. PamelaM commented on Jan 26, 2017

    @PamelaM
    CollaboratorAuthor

    Ned just released django-coverage-plugin==1.4.1 which should address the problems dealing wit deferred initialization of the backends.

    Please check it out and let us know if it works for you.

  5. garyayo commented on Jan 26, 2017

    @garyayo

    @PamelaM Thank you for getting back to me, I appreciate your response.

    Since upgrading to django-coverage-plugin==1.4.1 we're now experiencing the following issue.

    (backend) [8:55:09] gary:backend git:(dev*) $ pip freeze | grep coverage
    coverage==4.3.4
    django-coverage-plugin==1.4.1
    (backend) [8:55:14] gary:backend git:(dev*) $ coverage run ./manage.py test -v 2
    Coverage.py warning: Disabling plugin 'django_coverage_plugin.DjangoTemplatePlugin' due to an exception:
    Traceback (most recent call last):
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/coverage/control.py", line 476, in _should_trace_internal
        file_tracer = plugin.file_tracer(canonical)
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.py", line 163, in file_tracer
        self.debug_checked = check_debug()
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.py", line 67, in check_debug
        for engine in django.template.engines.all():
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django/template/utils.py", line 110, in all
        return [self[alias] for alias in self]
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django/template/utils.py", line 101, in __getitem__
        engine = engine_cls(params)
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django/template/backends/django.py", line 31, in __init__
        options['libraries'] = self.get_templatetag_libraries(libraries)
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django/template/backends/django.py", line 49, in get_templatetag_libraries
        libraries = get_installed_libraries()
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django/template/backends/django.py", line 132, in get_installed_libraries
        for app_config in apps.get_app_configs())
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
        self.check_apps_ready()
      File "/home/gary/dev/envs/backend/local/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
        raise AppRegistryNotReady("Apps aren't loaded yet.")
    AppRegistryNotReady: Apps aren't loaded yet.
    
    

    Unfortunately it seems as if our best option at this point is to downgrade to django-coverage-plugin==1.3.1

  6. PamelaM commented on Jan 26, 2017

    @PamelaM
    CollaboratorAuthor

    I'll keep plugging away this weekend. I can see where you're getting the error, now I just need to figure out what my integration test environment is doing differently than your environment (since I'm not getting that error).

    It's probably time to step back and rethink every part of the startup process. I'll probably also remove support for DJ 1.7 and earlier - if only to simplify the plugin.

    Clearly, there are a number of variables. I see that you're running "Python==2.7.(something)". I'll assume you're still on "Django==1.9" and focus on that.

  7. garyayo commented on Jan 26, 2017

    @garyayo

    Thanks @PamelaM.

    You're correct. The error is occurring within our backend environment which is setup as

    (backend) [9:38:06] gary:backend git:(dev*) $ python --version
    Python 2.7.12
    (backend) [9:38:36] gary:backend git:(dev*) $ pip freeze | grep Django
    Django==1.9
    (backend) [9:38:41] gary:backend git:(dev*) $ pip freeze | grep coverage
    coverage==4.3.4
    django-coverage-plugin==1.4.1 
    (backend) [9:38:47] gary:backend git:(dev*) $
    

    Thanks again. Please let me know if you need any additional information.

  8. PamelaM commented on Jan 31, 2017

    @PamelaM
    CollaboratorAuthor

    @garyayo Could you try with PR #38?
    I think the fix will address both your issue and a number of other, similar ones.

    Please let me know if it works for you.

    Thanks
    Pam

  9. garyayo commented on Feb 2, 2017

    @garyayo

    @PamelaM Sorry for the delay in my response.

    Any idea how I would be able to pull in that PR through pip? I have tried the following command with your PR commit pip install git+https://github.com/nedbat/django_coverage_plugin.git@4df203a0908ac638f6c6da2b2e53096eb29506e8 with no luck.

    Would love to test out that PR for you.

  10. clokep commented on Feb 2, 2017

    @clokep

    @garyayo Use the following:
    pip install https://codeload.github.com/nedbat/django_coverage_plugin/zip/4df203a0908ac638f6c6da2b2e53096eb29506e8

    Note that if you already have django-coverage-plugin 1.4.1 installed pip won't upgrade to the new code because it's the same version number.

  11. garyayo commented on Feb 2, 2017

    @garyayo

    Very excellent! Thank you @clokep!

    @PamelaM I've very happy to say that my issue appears to have been resolved!

    (backend) [9:10:42] gary:backend git:(dev*) $ pip install https://codeload.github.com/nedbat/django_coverage_plugin/zip/4df203a0908ac638f6c6da2b2e53096eb29506e8
    Collecting https://codeload.github.com/nedbat/django_coverage_plugin/zip/4df203a0908ac638f6c6da2b2e53096eb29506e8
      Downloading https://codeload.github.com/nedbat/django_coverage_plugin/zip/4df203a0908ac638f6c6da2b2e53096eb29506e8
         | 30kB 942kB/s
    Requirement already satisfied: Django>=1.4 in /home/gary/dev/envs/backend/lib/python2.7/site-packages (from django-coverage-plugin==1.4.2)
    Requirement already satisfied: coverage>=4.0 in /home/gary/dev/envs/backend/lib/python2.7/site-packages (from django-coverage-plugin==1.4.2)
    Requirement already satisfied: six>=1.4.0 in /home/gary/dev/envs/backend/lib/python2.7/site-packages (from django-coverage-plugin==1.4.2)
    Installing collected packages: django-coverage-plugin
      Running setup.py install for django-coverage-plugin ... done
    Successfully installed django-coverage-plugin-1.4.2
    (backend) [9:13:54] gary:backend git:(dev*) $ pip freeze | grep coverage
    coverage==4.3.4
    django-coverage-plugin==1.4.2
    (backend) [9:14:00] gary:backend git:(dev*) $ pip freeze | grep Django
    Django==1.9
    (backend) [9:11:11] gary:backend git:(dev*) $ coverage run ./manage.py test v4.test.test_scheduler -v 2
    Creating test database for alias 'default' 
    

    Thanks for all the hard work.

  12. PamelaM commented on Feb 7, 2017

    @PamelaM
    CollaboratorAuthor

    Excellent! Thanks for checking!

  13. PamelaM commented on Feb 7, 2017

    @PamelaM
    CollaboratorAuthor

    Fixed by version 1.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions