schemathesis / schemathesis

Supercharge your API testing, catch bugs, and ensure compliance

Home Page:https://schemathesis.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] TypeError

obscurebyron opened this issue · comments

Checklist

  • I checked the FAQ section of the documentation
  • I looked for similar issues in the issue tracker
  • I am using the latest version of Schemathesis

Describe the bug

Occasionally, while running against our API, we'll see an internal error reported, which follows.

To Reproduce

🚨 Mandatory 🚨: Steps to reproduce the behavior:

  1. Our code is private, I am disallowed to provide detailed steps. But this is the command we run:
st run --checks all https://turkey.spicedchai.com/woowoo/openapi.json \
--experimental=openapi-3.1 \
-H 'jwt: .JWT_CONTENT_HERE.' \
-H "foo: BAR" \
--show-trace  \
--base-url=https://turkey.spicedchai.com/woowoo  \
-M GET \
--request-timeout 100

Expected behavior

Ordinary run, with negative cases reported

Actual behavior

Schemathesis crashes with a stack trace

Environment

- OS: Apple M1 Pro 
- Python version: 3.11
- Schemathesis version: 3.28.1
- Spec version: [e.g. Open API 3.1]

Additional context

Schema location: https://turkey.spicedchai.com/woowoo/openapi.json
Base URL: https://turkey.spicedchai.com/woowoo
Specification version: Open API 3.1.0
Random seed: 312018194680697670799599384726727557321
Workers: 1
Collected API operations: 33
Collected API links: 0
API probing: SUCCESS
Schema analysis: SKIP

GET /woowoo/api/user F                                                                                                                                                                                                                                                                                                                                                  [  3%]
GET /woowoo/api/user/profile F                                                                                                                                                                                                                                                                                                                                          [  6%]
GET /woowoo/api/user/me .                                                                                                                                                                                                                                                                                                                                               [  9%]
GET /woowoo/api/user/banana/count .                                                                                                                                                                                                                                                                                                                               [ 12%]
GET /woowoo/api/user/profile/{identifier} F                                                                                                                                                                                                                                                                                                                             [ 15%]
GET /woowoo/api/user/{identifier} F                                                                                                                                                                                                                                                                                                                                     [ 18%]
GET /woowoo/api/file/metadata .                                                                                                                                                                                                                                                                                                                                         [ 21%]
GET /woowoo/api/file/metadata/{identifier} Test Execution Error

An internal error occurred during the test run

    Traceback (most recent call last):
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/cli/__init__.py", line 1110, in into_event_stream
        yield from runner.from_schema(
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/impl/core.py", line 194, in _generate_events
        yield from self._execute(results, stop_event)
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/impl/solo.py", line 24, in _execute
        for event in self._execute_impl(results):
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/impl/solo.py", line 32, in _execute_impl
        yield from self._run_tests(
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/impl/core.py", line 255, in _run_tests
        for event in run_test(
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/impl/core.py", line 560, in run_test
        yield events.AfterExecution.from_result(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/events.py", line 198, in from_result
        result=SerializedTestResult.from_test_result(result),
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/serialization.py", line 436, in from_test_result
        errors=[SerializedError.from_exception(error) for error in result.errors],
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/serialization.py", line 436, in <listcomp>
        errors=[SerializedError.from_exception(error) for error in result.errors],
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/runner/serialization.py", line 250, in from_exception
        message, extras = extract_requests_exception_details(exception)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/foobar/dev/work/yippee/chunkymonkey/my-application/.venv/lib/python3.11/site-packages/schemathesis/exceptions.py", line 555, in extract_requests_exception_details
        if ":" not in inner.reason.args[0]:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: argument of type 'HTTPConnection' is not iterable

Here is the portion of the openapi.json relating to the endpoint that failed:

 "/api/file/metadata/{identifier}": {
      "get": {
        "tags": [
          "file"
        ],
        "summary": "Retrieve File",
        "description": "(U) Get file metadata.",
        "operationId": "retrieve_file_api_file_metadata__identifier__get",
        "parameters": [
          {
            "name": "identifier",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid",
              "title": "Identifier"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileResponseModel"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },

Thank you for reporting,

It is indeed an issue. I don't have the time right now (as I am working on #2207 right now) but I will take a look at it as soon as possible.

The fix is released in 3.29.0 🎉

Great news! Much appreciated!

Cool! Let me know if there is anything else I can help with :) Btw, there was a small patch release - 3.29.1 (missed a performance in stateful tests)