Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate lazily loaded classes in deploy checks #12135

Open
2 tasks done
dleidert opened this issue Jul 26, 2024 · 3 comments
Open
2 tasks done

Validate lazily loaded classes in deploy checks #12135

dleidert opened this issue Jul 26, 2024 · 3 comments
Labels
enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed.

Comments

@dleidert
Copy link

Describe the issue

I run weblate in docker with an Apache reverse proxy setup. The docker-compose configuration contains a setting for WEBLATE_ADD_ADDONS. Now, I recently discovered that there was a "typo" in one of the add-ons listed there: weblate.addons.consistency.LangaugeConsistencyAddon. I then though, that I might have caused this typo myself, "fixed" it, and restarted the instance. Soon after, I started to observe internal server errors that were caught by Sentry. The Sentry backtrace shows this:

ImproperlyConfigured
Module 'weblate.addons.consistency' does not define a 'LanguageConsistencyAddon' class in WEBLATE_ADDONS

weblate/utils/classloader.py in load_class at line 29
[..]

Now, I do understand the error, and I changed the add-on name back to what seems to be the correct name. But shouldn't weblate handle this situation more gracefully than causing an internal server error? In my case, the error was thrown while I was creating a new component, which lead to empty translations in that component.

I already tried

  • I've read and searched the documentation.
  • I've searched for similar filed issues in this repository.

Steps to reproduce the behavior

  1. Create a docker-compose override file which contains e.g. WEBLATE_ADD_ADDONS=weblate.addons.consistency.LanguageConsistencyAddon.
  2. Start the instance
  3. Create a project and try to access the add-ons
  4. The instance fails with an internal server error

Expected behavior

Handle the situation more gracefully without causing an internal server error.

Screenshots

No response

Exception traceback

weblate/utils/classloader.py in load_class at line 29:

            f"Error importing module {module!r} in {setting}: {error}"
        ) from error
    try:
        return getattr(mod, attr)
    except AttributeError as error:
        raise ImproperlyConfigured(
              ^^^^^^^^^^^^^^^^^^^^
            f"Module {module!r} does not define a {attr!r} class in {setting}"
        ) from error
class ClassLoader:

How do you run Weblate?

Docker container

Weblate versions

  • Weblate: 5.6.2
  • Django: 5.0.6
  • siphashc: 2.4.1
  • translate-toolkit: 3.13.1
  • lxml: 5.2.2
  • pillow: 10.3.0
  • nh3: 0.2.17
  • python-dateutil: 2.9.0.post0
  • social-auth-core: 4.5.4
  • social-auth-app-django: 5.4.1
  • django-crispy-forms: 2.2
  • oauthlib: 3.2.2
  • django_compressor: 4.5
  • djangorestframework: 3.15.2
  • django-filter: 24.2
  • django-appconf: 1.0.6
  • user-agents: 2.2.0
  • filelock: 3.15.4
  • rapidfuzz: 3.9.3
  • openpyxl: 3.1.5
  • celery: 5.4.0
  • django-celery-beat: 2.6.0
  • kombu: 5.3.7
  • translation-finder: 2.16
  • weblate-language-data: 2024.5
  • html2text: 2024.2.26
  • pycairo: 1.26.1
  • PyGObject: 3.48.2
  • diff-match-patch: 20230430
  • requests: 2.32.3
  • django-redis: 5.4.0
  • hiredis: 2.3.2
  • sentry-sdk: 2.7.1
  • Cython: 3.0.10
  • misaka: 2.1.1
  • GitPython: 3.1.43
  • borgbackup: 1.2.8
  • pyparsing: 3.1.2
  • ahocorasick_rs: 0.22.0
  • python-redis-lock: 4.0.0
  • charset-normalizer: 3.3.2
  • Python: 3.12.4
  • Git: 2.39.2
  • psycopg: 3.2.1
  • psycopg-binary: 3.2.1
  • phply: 1.2.6
  • ruamel.yaml: 0.18.6
  • tesserocr: 2.7.0
  • boto3: 1.34.136
  • zeep: 4.2.1
  • aeidon: 1.15
  • iniparse: 0.5
  • mysqlclient: 2.2.4
  • Mercurial: 6.7.4
  • git-svn: 2.39.2
  • git-review: 2.4.0
  • PostgreSQL server: 16.3
  • Database backends: django.db.backends.postgresql
  • PostgreSQL implementation: psycopg3 (binary)
  • Cache backends: default:RedisCache, avatar:FileBasedCache
  • Email setup: django.core.mail.backends.smtp.EmailBackend: smtp.office365.com
  • OS encoding: filesystem=utf-8, default=utf-8
  • Celery: redis://cache:6379/1, redis://cache:6379/1, regular
  • Platform: Linux 6.1.0-18-amd64 (x86_64)

Weblate deploy checks

System check identified no issues (1 silenced).

Additional context

No response

@nijel nijel added the enhancement Adding or requesting a new feature. label Jul 26, 2024
@nijel nijel changed the title Improper add-on name leads to causing an internal server error Validate lazily loaded classes in deploy checks Jul 26, 2024
@nijel
Copy link
Member

nijel commented Jul 26, 2024

The classes are currently loaded on demand to avoid loading them when not needed. This will lead to raising ImproperlyConfigured errors at runtime.

Checking the validity of all ClassLoader instances should be probably done as deploy check so that it is visible while running weblate check --deploy and in the management interface.

@nijel nijel added hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed. good first issue Opportunity for newcoming contributors. labels Jul 26, 2024
Copy link

This issue seems to be a good fit for newbie contributors. You are welcome to contribute to Weblate! Don't hesitate to ask any questions you would have while implementing this.

You can learn about how to get started in our contributors documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed.
Projects
None yet
Development

No branches or pull requests

3 participants
@nijel @dleidert and others