WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.63k stars 1.02k forks source link

Internal Server Error due to violates not-null constraint #5926

Closed marcelofabricanti closed 3 years ago

marcelofabricanti commented 3 years ago

Describe the issue

The error "Internal Server Error" is shown at home screen.

I already tried

The error message already is already shown at home screen, you don't need to do anything else.

To Reproduce the issue

Steps to reproduce the behavior:

  1. Enter home screen.

Expected behavior

The website displays a message of "Internal Server Error" and the app's log prints the Exception traceback below.

Exception traceback

uwsgi stderr | [2021-04-26 17:50:20,368: ERROR/392] Internal Server Error: /
uwsgi stderr | Traceback (most recent call last):
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/backends/utils.py", line 84, in _execute
uwsgi stderr |     return self.cursor.execute(sql, params)
uwsgi stderr | psycopg2.errors.NotNullViolation: null value in column "secondary" of relation "metrics_metric" violates not-null constraint
uwsgi stderr | DETAIL:  Failing row contains (636, 2021-04-26, 0, 0, projects, 1, null).
uwsgi stderr |
uwsgi stderr |
uwsgi stderr | The above exception was the direct cause of the following exception:
uwsgi stderr |
uwsgi stderr | Traceback (most recent call last):
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/core/handlers/exception.py", line 47, in inner
uwsgi stderr |     response = get_response(request)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/core/handlers/base.py", line 181, in _get_response
uwsgi stderr |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
uwsgi stderr |     response = view_func(request, *args, **kwargs)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/weblate/trans/views/dashboard.py", line 205, in home
uwsgi stderr |     return dashboard_anonymous(request)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/weblate/trans/views/dashboard.py", line 328, in dashboard_anonymous
uwsgi stderr |     Metric.SCOPE_GLOBAL, 0, name="projects"
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/models/manager.py", line 85, in manager_method
uwsgi stderr |     return getattr(self.get_queryset(), name)(*args, **kwargs)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/weblate/metrics/models.py", line 46, in get_current
uwsgi stderr |     collect_global()
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/weblate/metrics/tasks.py", line 74, in collect_global
uwsgi stderr |     for name, value in data.items()
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/models/manager.py", line 85, in manager_method
uwsgi stderr |     return getattr(self.get_queryset(), name)(*args, **kwargs)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/models/query.py", line 507, in bulk_create
uwsgi stderr |     objs_without_pk, fields, batch_size, ignore_conflicts=ignore_conflicts,
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/models/query.py", line 1274, in _batched_insert
uwsgi stderr |     ignore_conflicts=ignore_conflicts,
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/models/query.py", line 1254, in _insert
uwsgi stderr |     return query.get_compiler(using=using).execute_sql(returning_fields)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/models/sql/compiler.py", line 1397, in execute_sql
uwsgi stderr |     cursor.execute(sql, params)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/backends/utils.py", line 66, in execute
uwsgi stderr |     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
uwsgi stderr |     return executor(sql, params, many, context)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/backends/utils.py", line 84, in _execute
uwsgi stderr |     return self.cursor.execute(sql, params)
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/utils.py", line 90, in __exit__
uwsgi stderr |     raise dj_exc_value.with_traceback(traceback) from exc_value
uwsgi stderr |   File "/usr/local/lib/python3.7/dist-packages/django/db/backends/utils.py", line 84, in _execute
uwsgi stderr |     return self.cursor.execute(sql, params)
uwsgi stderr | django.db.utils.IntegrityError: null value in column "secondary" of relation "metrics_metric" violates not-null constraint
uwsgi stderr | DETAIL:  Failing row contains (636, 2021-04-26, 0, 0, projects, 1, null).

Server configuration and status

Weblate installation: Docker (Kubernetes > AWS EKS)

weblate@weblate-api-7978fcf4ff-9h8nm:/$ weblate list_versions

Weblate deploy checks

weblate@weblate-api-7978fcf4ff-9h8nm:/$ weblate check --deploy SystemCheckError: System check identified some issues:

CRITICALS: ?: (weblate.E027) The path /app/data/settings-override.py is owned by a different user, check your DATA_DIR settings. HINT: https://docs.weblate.org/en/weblate-4.5.1/admin/install.html#file-permissions

INFOS: ?: (weblate.I021) Error collection is not set up, it is highly recommended for production use HINT: https://docs.weblate.org/en/weblate-4.5.1/admin/install.html#collecting-errors ?: (weblate.I028) Backups are not configured, it is highly recommended for production use HINT: https://docs.weblate.org/en/weblate-4.5.1/admin/backup.html ?: (weblate.I031) New Weblate version is available, please upgrade to 4.6. HINT: https://docs.weblate.org/en/weblate-4.5.1/admin/upgrade.html

System check identified 4 issues (1 silenced).

Workaround Solution

Table before: image

To workaround this (and reestabilish production), I did execute this command in DB: ALTER TABLE weblate.metrics_metric ALTER COLUMN secondary SET DEFAULT 0;

After that, the problem has been solved (palliative).

Table after: image

nijel commented 3 years ago

Seems like you are running Weblate 4.5.1 with database upgraded to 4.5.3...

PS: The secondary column was introduced by e0ba892f8ef3c6c7c96e8f55e7241c154abdfc81.

github-actions[bot] commented 3 years ago

This issue looks more like a support question than an issue. We strive to answer these reasonably fast, but purchasing the support subscription is not only more responsible and faster for your business but also makes Weblate stronger. In case your question is already answered, making a donation is the right way to say thank you!

marcelofabricanti commented 3 years ago

You were totally right.

I probably made a mistake on Apr/14/21 and ran version 4.5.3 by mistake, which applied some migration and broke my environment.

I have now tried to run version 4.5.3-3 and 4.6-1, without success. The login screen appears without formatting and after a long time two files (one .js and one .css) abort with an ERR_INCOMPLETE_CHUNKED_ENCODING error. But no errors in the application's log.

Tried different browsers (chrome, firefox, safari), tried flush redis, restart weblate pod.... notting helped.

I restored a DB backup of the day Apr/13/21 and it is running in version 4.5.1-1 without problems.

Thank you very much for your time and I'm sorry for the inconvenience.

github-actions[bot] commented 3 years ago

The issue you have reported is now resolved. If you don’t feel it’s right, please follow its labels to get a clue for further steps.