Skip to content

Commit

Permalink
fix: Added null safeguard before saving job description
Browse files Browse the repository at this point in the history
  • Loading branch information
irfanuddinahmad committed Aug 21, 2024
1 parent e28f82a commit 6aada61
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Change Log
Unreleased

[1.51.1] - 2024-08-21
---------------------
* feat: Added safeguard for nulls before saving job description

[1.51.0] - 2024-07-03
---------------------
* feat: Replaced client for ai chat
Expand Down
2 changes: 1 addition & 1 deletion taxonomy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# 2. MINOR version when you add functionality in a backwards compatible manner, and
# 3. PATCH version when you make backwards compatible bug fixes.
# More details can be found at https://semver.org/
__version__ = '1.51.0'
__version__ = '1.51.1'

default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name
5 changes: 3 additions & 2 deletions taxonomy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,9 @@ def generate_and_store_job_description(job_external_id, job_name):
"""
prompt = settings.JOB_DESCRIPTION_PROMPT.format(job_name=job_name)
description = chat_completion(prompt)
Job.objects.filter(external_id=job_external_id).update(description=description)
LOGGER.info('Generated description for Job: [%s], Prompt: [%s]', job_name, prompt)
if description:
Job.objects.filter(external_id=job_external_id).update(description=description)
LOGGER.info('Generated description for Job: [%s], Prompt: [%s]', job_name, prompt)


def generate_and_store_job_to_job_description(current_job, future_job):
Expand Down
26 changes: 25 additions & 1 deletion tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@
from taxonomy.constants import ENGLISH
from taxonomy.emsi.client import EMSISkillsApiClient
from taxonomy.exceptions import SkipProductProcessingError, TaxonomyAPIError
from taxonomy.models import CourseSkills, Industry, JobSkills, Skill, Translation, XBlockSkillData, XBlockSkills
from taxonomy.models import (
CourseSkills,
Industry,
Job,
JobSkills,
Skill,
Translation,
XBlockSkillData,
XBlockSkills,
)
from test_utils import factories
from test_utils.constants import COURSE_KEY, PROGRAM_UUID, USAGE_KEY
from test_utils.decorators import mock_api_response
Expand Down Expand Up @@ -1170,3 +1179,18 @@ def test_duplicate_model_instance_with_dates(self):
assert original_industry.id != new_instance.id
assert not hasattr(new_industry, "created")
assert not hasattr(new_industry, "modified")

@ddt.data(None, 'some text')
@mock.patch('taxonomy.utils.chat_completion')
def test_generate_and_store_job_description(self, description, mock_chat_completion):
"""
Validate that `generate_and_store_job_description` handles a null job description correctly
"""
job = factories.JobFactory()
mock_chat_completion.return_value = description
utils.generate_and_store_job_description(job.external_id, job.name)
updated_job = Job.objects.get(external_id=job.external_id)
if description:
assert updated_job.description == description
else:
assert updated_job.description == job.description

0 comments on commit 6aada61

Please sign in to comment.