Skip to content

[Bug] add_attachment_to_result called with result_id None when uploading to pre-created empty run #404

@ttisdon-thryv

Description

@ttisdon-thryv

Description

When using parse_junit with a --run-id to upload results to a TestRail run that was created empty (via API with include_all: false and no case_ids), trcli successfully adds results for test cases but fails to upload attachments.
The TestRail API returns 400 with 'error': 'Field :result_id is not a valid ID.' and the request URL is /api/v2/add_attachment_to_result/None.

Steps to reproduce

  1. Create a TestRail run via API with include_all: false and no case_ids (empty run) and capture the run id from the response.
  2. Run tests and produce a JUnit XML that includes at least one failed test with a testrail_attachment property. (I used Playwright and a custom reporter to set testrail_attachment on failed tests)
  3. Run trcli:
    trcli -y -h $HOST --verbose --project $PROJECT --username $UN --password $PW parse_junit -f ".output/junit/results.xml" --title "$RUN_TITLE_WITH_CI_BUILD_NUM" --suite-id $SUITE_ID --run-id $RUN_ID
  4. Observe the upload: results are added for cases but the attachment upload fails

Expected result

Attachments are uploaded to the correct result. trcli should use the result_id returned from add_result_for_case (or refresh the run’s tests/results after adding results) so that add_attachment_to_result is called with a valid result_id for each case that has an attachment.

Actual result

trcli calls add_attachment_to_result with result_id=None. TestRail responds with 400 and the upload fails:

URL: .../api/v2/add_attachment_to_result/None
Response: {'error': 'Field :result_id is not a valid ID.'}
Message: Failed to upload attachment 'test-failed-1.png' for case 2342759: Field :result_id is not a valid ID.

100% 180/180 [00:01<00:00, 136.61it/s, Done.]
Uploading 42 attachments for 17 test results.

**** API Call
method: POST
url: ****************************************/api/v2/add_attachment_to_result/None
headers:
  User-Agent: TRCLI
  X-Uploader-Metadata: *****
response status code: 400
response body: {'error': 'Field :result_id is not a valid ID.'}
****
Failed to upload attachment 'test-failed-1.png' for case 2342797: Field :result_id is not a valid ID.
...
...
...

Warning: 42 attachment(s) failed to upload.

Severity

S3 Moderate — degraded experience, workaround exists

Reproducibility

Always (100%)

Language and runtime versions

Node 20.x (for generating JUnit); Python/runtime as used by trcli 1.13.3.

Framework and library versions

Playwright 1.52.0; trcli 1.13.3.

CI provider (if applicable)

CircleCI

OS and architecture

Linux (CircleCI default image), x86_64

Provide the command(s) used

CREATE EMPTY TESTRAIL RUN COMMAND
curl -s -X POST "${HOST}/api/v2/add_run/${PROJECT_ID}" -H "Content-Type: application/json" -u "$UN:$PW" -d '{"suite_id": '"$SUITE_ID"', "name": "'"$RUN_TITLE"'", "include_all": false}'

UPLOAD PLAYWRIGHT RESULTS COMMAND
trcli -y -h $HOST--verbose --project "ProjectName" --username $UN --password $PW parse_junit -f "./output/junit/results.xml" --title "Run title (${CIRCLE_BUILD_NUM})" --suite-id $SUITE_ID --run-id $RUN_ID

Affected TestRail version

TestRail v10.1.1 Default (1011)

Affected CLI version

1.13.3

Logs and diagnostics

**** API Call
method: POST
url: ****************************************/api/v2/add_attachment_to_result/None
headers:
  User-Agent: TRCLI
  X-Uploader-Metadata: eyJ...
response status code: 400
response body: {'error': 'Field :result_id is not a valid ID.'}
****
Failed to upload attachment 'test-failed-1.png' for case 2342759: Field :result_id is not a valid ID.

Attachments

No response

Workaround

None that preserves “pre-create empty run, then upload results and attachments.” However, I can set include_all: true and this issue doesn't occur, but I don't want all the cases in the suite added to the run, only the tests executed during the Playwright run.

Pre-submission checks

  • I searched for existing issues and discussions
  • I masked secrets and personal data

Metadata

Metadata

Labels

TriageThis issue currently being reviewed by the TestRail team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions