Skip to content

Commit a5b1598

Browse files
Merge pull request #201 from openedx/iahmad/ENT-9347
fix: Added null safeguard before saving job description
2 parents e28f82a + f26a3ce commit a5b1598

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Change Log
1313
1414
Unreleased
1515

16+
[1.51.1] - 2024-08-21
17+
---------------------
18+
* feat: Added safeguard for nulls before saving job description
19+
1620
[1.51.0] - 2024-07-03
1721
---------------------
1822
* feat: Replaced client for ai chat

taxonomy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
# 2. MINOR version when you add functionality in a backwards compatible manner, and
1616
# 3. PATCH version when you make backwards compatible bug fixes.
1717
# More details can be found at https://semver.org/
18-
__version__ = '1.51.0'
18+
__version__ = '1.51.1'
1919

2020
default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name

taxonomy/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,9 @@ def generate_and_store_job_description(job_external_id, job_name):
752752
"""
753753
prompt = settings.JOB_DESCRIPTION_PROMPT.format(job_name=job_name)
754754
description = chat_completion(prompt)
755-
Job.objects.filter(external_id=job_external_id).update(description=description)
756-
LOGGER.info('Generated description for Job: [%s], Prompt: [%s]', job_name, prompt)
755+
if description:
756+
Job.objects.filter(external_id=job_external_id).update(description=description)
757+
LOGGER.info('Generated description for Job: [%s], Prompt: [%s]', job_name, prompt)
757758

758759

759760
def generate_and_store_job_to_job_description(current_job, future_job):

tests/test_utilities.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from taxonomy.constants import ENGLISH
1717
from taxonomy.emsi.client import EMSISkillsApiClient
1818
from taxonomy.exceptions import SkipProductProcessingError, TaxonomyAPIError
19-
from taxonomy.models import CourseSkills, Industry, JobSkills, Skill, Translation, XBlockSkillData, XBlockSkills
19+
from taxonomy.models import CourseSkills, Industry, Job, JobSkills, Skill, Translation, XBlockSkillData, XBlockSkills
2020
from test_utils import factories
2121
from test_utils.constants import COURSE_KEY, PROGRAM_UUID, USAGE_KEY
2222
from test_utils.decorators import mock_api_response
@@ -1170,3 +1170,18 @@ def test_duplicate_model_instance_with_dates(self):
11701170
assert original_industry.id != new_instance.id
11711171
assert not hasattr(new_industry, "created")
11721172
assert not hasattr(new_industry, "modified")
1173+
1174+
@ddt.data(None, 'some text')
1175+
@mock.patch('taxonomy.utils.chat_completion')
1176+
def test_generate_and_store_job_description(self, description, mock_chat_completion):
1177+
"""
1178+
Validate that `generate_and_store_job_description` handles a null job description correctly
1179+
"""
1180+
job = factories.JobFactory()
1181+
mock_chat_completion.return_value = description
1182+
utils.generate_and_store_job_description(job.external_id, job.name)
1183+
updated_job = Job.objects.get(external_id=job.external_id)
1184+
if description:
1185+
assert updated_job.description == description
1186+
else:
1187+
assert updated_job.description == job.description

0 commit comments

Comments
 (0)