openedx / course-discovery

Service providing access to consolidated course and program metadata
https://edx-discovery.readthedocs.io/en/latest/
GNU Affero General Public License v3.0
57 stars 173 forks source link

Fix: [ENT-8400]: added transcript_languages_search_facet_names to CourseRunSerializer #4302

Closed mahamakifdar19 closed 7 months ago

mahamakifdar19 commented 7 months ago

Ticket

ENT-8400

Description

Resolution

I've added a validation check to verify the existence of the corresponding name_t (Name for translation) in the LanguageTagTranslation model before accessing it, furthermore I have disabled the translation flag for get_transcript_languages_search_facet_names because we do not require translated transcript language names, and not all languages stored in transcript_languages have a corresponding name for translation stored.

File "/edx/app/discovery/discovery/course_discovery/apps/api/serializers.py", line 1096, in get_transcript_languages_search_facet_names
    transcript_languages_facet_names.append(language.get_search_facet_display(translate=True))
  File "/edx/app/discovery/discovery/course_discovery/apps/ietf_language_tags/models.py", line 29, in get_search_facet_display
    return self.translated_macrolanguage if translate else self.macrolanguage
  File "/edx/app/discovery/discovery/course_discovery/apps/ietf_language_tags/models.py", line 22, in translated_macrolanguage
    return self.name_t.split('-')[0].strip()
  File "/edx/app/discovery/venvs/discovery/lib/python3.8/site-packages/parler/fields.py", line 142, in __get__
    translation = instance._get_translated_model(use_fallback=True, meta=meta)
  File "/edx/app/discovery/venvs/discovery/lib/python3.8/site-packages/parler/models.py", line 620, in _get_translated_model
    raise meta.model.DoesNotExist(
parler.models.DoesNotExist: language tag does not have a translation for the current language!
language tag ID #tl, language=en (tried fallbacks en)
Attempted to read attribute name_t.