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

fix: Fix Source matching query does not exist error #4191

Merged

Conversation

ziafazal
Copy link
Contributor

While setting up course discovery for first time refresh_course_metadata command breaks with this error.

Traceback (most recent call last):
  File "/openedx/discovery/course_discovery/apps/course_metadata/management/commands/refresh_course_metadata.py", line 37, in execute_loader
    run_loader()
  File "/openedx/venv/lib/python3.8/site-packages/backoff/_sync.py", line 105, in retry
    ret = target(*args, **kwargs)
  File "/openedx/discovery/course_discovery/apps/course_metadata/management/commands/refresh_course_metadata.py", line 34, in run_loader
    return loader_class(*loader_args).ingest()
  File "/openedx/discovery/course_discovery/apps/course_metadata/data_loaders/api.py", line 51, in __init__
    self.default_product_source = Source.objects.get(slug=settings.DEFAULT_PRODUCT_SOURCE_SLUG)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(
course_discovery.apps.course_metadata.models.Source.DoesNotExist: Source matching query does not exist.

Reason for this is we don't have and entry with settings.DEFAULT_PRODUCT_SOURCE_SLUG in Source of coursemetadata app.

This PR creates entry with settings.DEFAULT_PRODUCT_SOURCE_SLUG in Source if it does not exist to get rid of Source matching query does not exist error.

@@ -48,7 +48,7 @@ class CoursesApiDataLoader(AbstractDataLoader):

def __init__(self, partner, api_url=None, max_workers=None, is_threadsafe=False, enable_api=True):
super().__init__(partner, api_url, max_workers, is_threadsafe, enable_api)
self.default_product_source = Source.objects.get(slug=settings.DEFAULT_PRODUCT_SOURCE_SLUG)
self.default_product_source, __ = Source.objects.get_or_create(name=settings.DEFAULT_PRODUCT_SOURCE_SLUG, slug=settings.DEFAULT_PRODUCT_SOURCE_SLUG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is not necessarily the same as slug (edX vs edx).

@ziafazal ziafazal force-pushed the ziafazal/fix-source-doesnotexit branch 2 times, most recently from 6448afe to 4f4f163 Compare November 23, 2023 09:04
@dyudyunov
Copy link
Contributor

@ziafazal are you going to create a backport-PR to Quince?

Comment on lines 739 to 740
DEFAULT_PRODUCT_SOURCE_NAME = ''
DEFAULT_PRODUCT_SOURCE_SLUG = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please set name to 'edX' and slug to 'edx' to ensure it does not cause issue when attempting to create the first object.

fix: fix quality issue and reviewer feedback

fix: broken test

fix: broken test

fix: broken test

fix: broken test

chore: reviewer feedback
@DawoudSheraz DawoudSheraz merged commit c2638e4 into openedx:master Nov 24, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants