reportportal/client-Python

RP session does not log anything when it fails to log an attachment that is too large

shague opened this issue · 4 comments

Describe the bug
The RP session does not have any logs after an error occurs from trying to attach a large file that is larger than the configured maximum. In this case the max is 128Mb and the file is 160Mb. The RP session is opened, logs created, then the large log raises an exception and no logs are on RP for the session.

reportportal_client.errors.ResponseError: 5000: Unclassified error [Maximum upload size of 134217728 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (161505748) exceeds the configured maximum (134217728)]

Test Code to Reproduce

import logging
import os

import pytest
from reportportal_client.errors import ResponseError


@pytest.mark.parametrize("log_file", ["/tmp/small.txt", "/tmp/large.txt"])
def test_logs(log_file: str):
    rp_log = logging.getLogger(__name__)
    name = os.path.basename(log_file)
    with open(log_file, "r") as fp:
        data = fp.read()
        try:
            rp_log.info(
                f"ATTACHMENT: {name}",
                attachment={"name": name, "data": data, "mime": "text/plain",
                },
            )
        except ResponseError as err:
            if "Maximum upload size" in err:
                rp_log.info(f"Can't attach file - file is too large. name: {name}.\n{err}")
            else:
                raise err

Expected behavior
The exception can be caught in the client and other good logs should still be available in the RP session.

Or please provide a workaround to properly handle the exception.

Versions:

  • Mac, Chrome Version 103.0.5060.114 (Official Build) (x86_64)
  • Version of RP [find it under Login form, copy as is]
  • Current version:API Service: 5.6.3;Jobs Service: 5.6.3;Authorization Service: 5.6.3;Service UI: 5.6.0;
  • pytest-reportportal==5.0.11

The following issue has the same cause, though in that issue the author is looking for a method to increase the maximum attachment size instead of handling the exception and continuing. reportportal/reportportal#1533

@shague You are using outdated version of pytest-reportportal, please use the latest one: https://pypi.org/project/pytest-reportportal/5.1.2/

Is there a different workaround so the older version can continue to be used? Bringing in the new RP brings in different issues so we can't upgrade yet.