codecov / codecov/self-hosted

models.Owner.DoesNotExist: Owner matching query does not exist.

Open
#49 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
544
Forks
61
PR merge metrics
No merged PRs in 30d

Description

When login with github callback, I got a error:

{"error": "Server Error (500)"}

In api container, it raises an error:

{
  "message": "Internal Server Error: /login/github",
  "asctime": "2024-12-18 14:52:45,187",
  "name": "django.request",
  "levelname": "ERROR",
  "lineno": 241,
  "pathname": "/usr/local/lib/python3.12/site-packages/django/utils/log.py",
  "funcName": "log_response",
  "threadName": "MainThread",
  "exc_info": "xxxx",
  "taskName": null,
  "status_code": 500,
  "request": "<WSGIRequest: GET '/login/github?code=xx&state=xx'>",
  "utctime": "2024-12-18T14:52:45.187000",
  "logger.name": "django.request",
  "logger.thread_name": "MainThread",
  "level": "ERROR"
}

The exc_info details:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.12/site-packages/django/db/models/query.py\", line 916, in get_or_create
    return self.get(**kwargs), False
           ^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/django/db/models/query.py\", line 637, in get
    raise self.model.DoesNotExist(
shared.django_apps.codecov_auth.models.Owner.DoesNotExist: Owner matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.12/site-packages/django/core/handlers/exception.py\", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/django/core/handlers/base.py\", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/django/views/generic/base.py\", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/django/views/generic/base.py\", line 143, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/app/codecov_auth/views/github.py\", line 139, in get
    return self.actual_login_step(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/app/codecov_auth/views/github.py\", line 122, in actual_login_step
    owner = self.get_and_modify_owner(user_dict, request)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/app/codecov_auth/views/base.py\", line 268, in get_and_modify_owner
    owner, is_new_user = self._get_or_create_owner(user_dict, request)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/app/codecov_auth/views/base.py\", line 363, in _get_or_create_owner
    owner, was_created = Owner.objects.get_or_create(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/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.12/site-packages/django/db/models/query.py\", line 923, in get_or_create
    return self.create(**params), True
           ^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/django/db/models/query.py\", line 658, in create
    obj.save(force_insert=True, using=self.db)
  File \"/usr/local/lib/python3.12/site-packages/shared/django_apps/codecov_auth/models.py\", line 395, in save
    super().save(*args, **kwargs)
  File \"/usr/local/lib/python3.12/site-packages/django/db/models/base.py\", line 814, in save
    self.save_base(
  File \"/usr/local/lib/python3.12/site-packages/model_utils/tracker.py\", line 343, in inner
    return original(instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/django/db/models/base.py\", line 892, in save_base
    post_save.send(
  File \"/usr/local/lib/python3.12/site-packages/django/dispatch/dispatcher.py\", line 177, in send
    (receiver, receiver(signal=self, sender=sender, **named))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/app/codecov_auth/signals.py\", line 53, in update_owner
    ShelterPubsub.get_instance().publish(data)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/app/utils/shelter.py\", line 22, in get_instance
    cls._instance = cls()
                    ^^^^^
  File \"/app/utils/shelter.py\", line 27, in __init__
    self.pubsub_publisher = pubsub_v1.PublisherClient()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/google/cloud/pubsub_v1/publisher/client.py\", line 139, in __init__
    super().__init__(**kwargs)
  File \"/usr/local/lib/python3.12/site-packages/google/pubsub_v1/services/publisher/client.py\", line 492, in __init__
    self._transport = Transport(
                      ^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/google/pubsub_v1/services/publisher/transports/grpc.py\", line 153, in __init__
    super().__init__(
  File \"/usr/local/lib/python3.12/site-packages/google/pubsub_v1/services/publisher/transports/base.py\", line 104, in __init__
    credentials, _ = google.auth.default(
                     ^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.12/site-packages/google/auth/_default.py\", line 697, in default
    raise exceptions.DefaultCredentialsError(_CLOUD_SDK_MISSING_CREDENTIALS)
google.auth.exceptions.DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.

How can I fix this ?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with app/codecov_auth/views/github.py and app/codecov_auth/views/base.py to trace the callback into owner creation, then read app/codecov_auth/signals.py and app/utils/shelter.py where the traceback reaches Pub/Sub client initialization. Reproduce the GitHub callback with the documented local configuration and verify it no longer returns a 500 when the required credentials are available.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, github, google-cloud, python
Domain
authentication, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.