Skip to content

Commit

Permalink
fix: jobs files disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
ervandagadzhanyan committed Sep 19, 2024
1 parent 5a906ce commit 1ddb135
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jobs/jobs/db_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def change_job(
new_job_params: schemas.JobParamsToChange,
) -> None:
"""Changes any parameter of any job in db"""
new_job_params_dict = new_job_params.dict()
new_job_params_dict = new_job_params.dict(exclude_unset=True)
for job_param_key in new_job_params_dict:
if new_job_params_dict[job_param_key] is not None:
setattr(job, job_param_key, new_job_params_dict[job_param_key])
Expand Down
49 changes: 49 additions & 0 deletions jobs/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def create_mock_extraction_job_in_db(testing_session):
all_files_data=all_files_data,
status=schemas.Status.pending,
categories=["label"],
pipeline_engine="airflow",
previous_jobs=[100],
)
return result

Expand Down Expand Up @@ -208,3 +210,50 @@ def test_create_ImportJob(testing_session):
assert new_import_job
assert new_import_job.name == "MockImportJob"
assert new_import_job.type == schemas.JobType.ImportJob


def test_change_job_single_field(testing_session):
job = create_mock_extraction_job_in_db(testing_session)

new_params = schemas.JobParamsToChange(status=schemas.Status.in_progress)
db_service.change_job(
db=testing_session, job=job, new_job_params=new_params
)

updated_job = db_service.get_job_in_db_by_id(testing_session, job.id)

assert updated_job.name == job.name
assert updated_job.status == schemas.Status.in_progress.value
assert updated_job.files == job.files
assert updated_job.datasets == job.datasets
assert updated_job.previous_jobs == job.previous_jobs
assert updated_job.creation_datetime == job.creation_datetime
assert updated_job.type == job.type
assert updated_job.mode == job.mode


def test_change_job_many_fields(testing_session):
job = create_mock_extraction_job_in_db(testing_session)

new_params = schemas.JobParamsToChange(
status=schemas.Status.in_progress,
name="New",
files=[],
datasets=[1, 2, 3, 4],
previous_jobs=[],
type=schemas.JobType.ImportJob,
mode=schemas.JobMode.Automatic,
)
db_service.change_job(
db=testing_session, job=job, new_job_params=new_params
)

updated_job = db_service.get_job_in_db_by_id(testing_session, job.id)

assert updated_job.name == new_params.name
assert updated_job.status == new_params.status
assert updated_job.files == new_params.files
assert updated_job.datasets == new_params.datasets
assert updated_job.previous_jobs == new_params.previous_jobs
assert updated_job.type == new_params.type
assert updated_job.mode == new_params.mode

0 comments on commit 1ddb135

Please sign in to comment.