Skip to content

Commit 9cdca36

Browse files
committed
Fix getting info about sync release run in API
If the run fails, there is no PR and therefore no PR model which resulted in AttributeError when accessing the attributes of it. Fixes #2354
1 parent 18d732f commit 9cdca36

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

packit_service/service/api/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ def get_project_info_from_build(
5656

5757

5858
def get_sync_release_target_info(sync_release_model: SyncReleaseTargetModel):
59+
pr_model = sync_release_model.pull_request
5960
job_result_dict = {
6061
"status": sync_release_model.status,
6162
"branch": sync_release_model.branch,
6263
"downstream_pr_url": sync_release_model.downstream_pr_url,
63-
"downstream_pr_id": sync_release_model.pull_request.pr_id,
64-
"downstream_pr_project": sync_release_model.pull_request.project.project_url,
64+
"downstream_pr_id": pr_model.pr_id if pr_model else None,
65+
"downstream_pr_project": pr_model.project.project_url if pr_model else None,
6566
"submitted_time": optional_timestamp(sync_release_model.submitted_time),
6667
"start_time": optional_timestamp(sync_release_model.start_time),
6768
"finished_time": optional_timestamp(sync_release_model.finished_time),

tests_openshift/conftest.py

+18
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,24 @@ def pull_from_upstream_target_model(release_project_event_model):
359359
yield target_model
360360

361361

362+
@pytest.fixture()
363+
def pull_from_upstream_target_model_without_pr_model(release_project_event_model):
364+
pull_from_upstream_model, _ = SyncReleaseModel.create_with_new_run(
365+
status=SyncReleaseStatus.running,
366+
project_event_model=release_project_event_model,
367+
job_type=SyncReleaseJobType.pull_from_upstream,
368+
)
369+
370+
target_model = SyncReleaseTargetModel.create(
371+
status=SyncReleaseTargetStatus.submitted, branch=SampleValues.branch
372+
)
373+
target_model.set_finished_time(finished_time=datetime.datetime.utcnow())
374+
target_model.set_logs(logs="random logs")
375+
376+
pull_from_upstream_model.sync_release_targets.append(target_model)
377+
yield target_model
378+
379+
362380
@pytest.fixture()
363381
def propose_downstream_model_issue(an_issue_project_event_model):
364382
propose_downstream_model, _ = SyncReleaseModel.create_with_new_run(

tests_openshift/service/test_api.py

+15
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,21 @@ def test_detailed_propose_info_issue(
672672
assert response_dict["issue_id"] == SampleValues.issue_id
673673

674674

675+
def test_detailed_pull_from_upstream_without_pr_model(
676+
client, clean_before_and_after, pull_from_upstream_target_model_without_pr_model
677+
):
678+
response = client.get(
679+
url_for(
680+
"api.pull-from-upstream_pull_result",
681+
id=pull_from_upstream_target_model_without_pr_model.id,
682+
)
683+
)
684+
response_dict = response.json
685+
686+
assert response_dict["downstream_pr_project"] is None
687+
assert response_dict["downstream_pr_id"] is None
688+
689+
675690
@pytest.mark.parametrize(
676691
"key_to_check",
677692
[

0 commit comments

Comments
 (0)