codecov / self-hosted

Example of how to setup Codecov with docker compose
Other
447 stars 36 forks source link

Python traceback in codecov/self-hosted-api:rolling -- psycopg2.errors.UndefinedTable: relation "constants" does not exist #20

Closed gojun077 closed 1 year ago

gojun077 commented 1 year ago

Hi Codecov,

When migrating from codecov/enterprise-api:v5.0.1 to codecov/self-hosted-api:rolling, I am getting the following Python traceback:

/usr/local/lib/python3.9/site-packages/cerberus/validator.py:1607: UserWarning: No validation schema is defined for the arguments of rule 'check_aggregation_fields'
  warn(
{"message": "Internal Server Error: /", "asctime": "2023-09-11 10:52:30,193", "name": "django.request", "levelname": "ERROR", "lineno": 241, "pathname": "/usr/local/lib/python3.9/site-packages/django/utils/log.py", "funcName": "log_response", "threadName": "MainThread", "exc_info": "Traceback (most recent call last):
  File \"/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py\", line 89, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation \"constants\" does not exist
LINE 1: ...ELECT \"constants\".\"key\", \"constants\".\"value\" FROM \"constants...
                                                             ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py\", line 55, in inner
    response = get_response(request)
  File \"/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py\", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File \"/app/codecov/views.py\", line 8, in health
    version = Constants.objects.get(key=\"version\")
  File \"/usr/local/lib/python3.9/site-packages/django/db/models/manager.py\", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File \"/usr/local/lib/python3.9/site-packages/django/db/models/query.py\", line 633, in get
    num = len(clone)
  File \"/usr/local/lib/python3.9/site-packages/django/db/models/query.py\", line 380, in __len__
    self._fetch_all()
  File \"/usr/local/lib/python3.9/site-packages/django/db/models/query.py\", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File \"/usr/local/lib/python3.9/site-packages/django/db/models/query.py\", line 91, in __iter__
    results = compiler.execute_sql(
  File \"/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py\", line 1562, in execute_sql
    cursor.execute(sql, params)
  File \"/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py\", line 67, in execute
    return self._execute_with_wrappers(
  File \"/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py\", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File \"/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py\", line 89, in _execute
    return self.cursor.execute(sql, params)
  File \"/usr/local/lib/python3.9/site-packages/django/db/utils.py\", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File \"/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py\", line 89, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation \"constants\" does not exist
LINE 1: ...ELECT \"constants\".\"key\", \"constants\".\"value\" FROM \"constants...^",
"status_code": 500, "request": "<WSGIRequest: GET '/'>", "logger.name": "django.request", "logger.thread_name": "MainThread", "level": "ERROR"}

PR 106 from the codecov-api repo resolved the previous issue (No module named 'plan.service'..) when I tried the latest codecov/self-hosted-api:rolling image from Dockerhub.

This error seems to be related to the fact that we already have an existing Codecov v5 deployment with all the backend PostgreSQL tables created while using the codecov/enterprise-{api,frontend,gateway,worker} images; it seems the self-hosted-api image is looking for a different table that does not exist.

I think one workaround may be to create the necessary table constants manually -- could you give us some pointers for working around this issue?

Thanks

trent-codecov commented 1 year ago

After debugging this was related to django_migration_log table being empty. The easiest "fix" was to drop the db and re migrate. This was successful.