Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] HypothesisProvider.draw_string() got an unexpected keyword argument 'min_value' #2269

Open
3 tasks done
vrutkovs opened this issue Jun 18, 2024 · 3 comments
Open
3 tasks done
Assignees
Labels
Priority: High Important but not urgent Type: Bug Errors or unexpected behavior

Comments

@vrutkovs
Copy link

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

Schemathesis crashes if OpenAPI schema contains "min_value"

To Reproduce

🚨 Mandatory 🚨: Steps to reproduce the behavior:

TDB. Run st run ... --method PATCH https://<openshift API Server</openapi/v2

Traceback:

 PATCH /apis/performance.openshift.io/v1alpha1/performanceprofiles/{name}/status 
Runtime Error

HypothesisProvider.draw_string() got an unexpected keyword argument 'min_value'

    Traceback (most recent call last):
      File "/usr/local/lib/python3.12/site-packages/schemathesis/runner/impl/core.py", line 424, in run_test
        test(
      File "/usr/local/lib/python3.12/site-packages/schemathesis/runner/impl/core.py", line 780, in network_test
        case: Case,
                   ^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/core.py", line 1638, in wrapped_test
        raise the_error_hypothesis_found
      File "/usr/local/lib/python3.12/site-packages/hypothesis/core.py", line 1605, in wrapped_test
        state.run_engine()
      File "/usr/local/lib/python3.12/site-packages/hypothesis/core.py", line 1133, in run_engine
        runner.run()
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/engine.py", line 713, in run
        self._run()
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/engine.py", line 1165, in _run
        self.generate_new_examples()
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/engine.py", line 996, in generate_new_examples
        self.test_function(data)
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/engine.py", line 417, in test_function
        self.__stoppable_test_function(data)
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/engine.py", line 304, in __stoppable_test_function
        self._test_function(data)
      File "/usr/local/lib/python3.12/site-packages/hypothesis/core.py", line 1056, in _execute_once_for_engine
        escalate_hypothesis_internal_error()
      File "/usr/local/lib/python3.12/site-packages/hypothesis/core.py", line 1029, in _execute_once_for_engine
        result = self.execute_once(data)
                 ^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/core.py", line 946, in execute_once
        result = self.test_runner(data, run)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/core.py", line 734, in default_executor
        return function(data)
               ^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/core.py", line 857, in run
        kw, argslices = context.prep_args_kwargs_from_strategies(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/control.py", line 157, in prep_args_kwargs_from_strategies
        obj = check(self.data.draw(s, observe_as=f"generate:{k}"))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/data.py", line 2444, in draw
        return strategy.do_draw(self)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/strategies/_internal/lazy.py", line 167, in do_draw
        return data.draw(self.wrapped_strategy)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/data.py", line 2438, in draw
        return strategy.do_draw(self)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/strategies/_internal/core.py", line 1761, in do_draw
        return self.definition(data.draw, *self.args, **self.kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/schemathesis/specs/openapi/_hypothesis.py", line 179, in get_case_strategy
        body_ = ValueContainer(value=draw(strategy), location="body", generator=body_generator)
                                     ^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/data.py", line 2438, in draw
        return strategy.do_draw(self)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/strategies/_internal/lazy.py", line 167, in do_draw
        return data.draw(self.wrapped_strategy)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/data.py", line 2438, in draw
        return strategy.do_draw(self)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/strategies/_internal/core.py", line 1761, in do_draw
        return self.definition(data.draw, *self.args, **self.kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis_jsonschema/_from_schema.py", line 700, in from_object_schema
        key = draw(all_names_strategy.filter(lambda s: s not in out))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/data.py", line 2438, in draw
        return strategy.do_draw(self)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/strategies/_internal/lazy.py", line 167, in do_draw
        return data.draw(self.wrapped_strategy)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/data.py", line 2438, in draw
        return strategy.do_draw(self)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/strategies/_internal/strategies.py", line 1006, in do_draw
        result = self.do_filtered_draw(data)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/strategies/_internal/strategies.py", line 1016, in do_filtered_draw
        value = data.draw(self.filtered_strategy)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/data.py", line 2438, in draw
        return strategy.do_draw(self)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/strategies/_internal/strings.py", line 117, in do_draw
        return data.draw_string(
               ^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/hypothesis/internal/conjecture/data.py", line 2210, in draw_string
        value = self.provider.draw_string(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: HypothesisProvider.draw_string() got an unexpected keyword argument 'min_value'
    while generating 'case' from get_case_strategy(operation=APIOperation(path='/apis/performance.openshift.io/v1alpha1/performanceprofiles/{name}/status', method='patch', schema=<SwaggerV20 for Kubernetes v1.29.5+29c95f3>, verbose_name='PATCH /apis/performance.openshift.io/v1alpha1/performanceprofiles/{name}/status', app=None, base_url='https://api.vrutkovs.devcluster.openshift.com:6443/', path_parameters=ParameterSet(items=[OpenAPI20Parameter(definition={'uniqueItems': True, 'type': 'string', 'description': 'name of the PerformanceProfile', 'name': 'name', 'in': 'path', 'required': True})]), headers=ParameterSet(items=[OpenAPI20Parameter(definition={'name': 'authorization', 'required': True, 'in': 'header', 'type': 'string'})]), cookies=ParameterSet(items=[]), query=ParameterSet(items=[OpenAPI20Parameter(definition={'uniqueItems': True, 'type': 'string', 'description': 'When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed', 'name': 'dryRun', 'in': 'query'}), OpenAPI20Parameter(definition={'uniqueItems': True, 'type': 'string', 'description': 'fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. This field is required for apply requests (application/apply-patch) but optional for non-apply patch types (JsonPatch, MergePatch, StrategicMergePatch).', 'name': 'fieldManager', 'in': 'query'}), OpenAPI20Parameter(definition={'uniqueItems': True, 'type': 'string', 'description': 'fieldValidation instructs the server on how to handle objects in the request (POST/PUT/PATCH) containing unknown or duplicate fields. Valid values are: - Ignore: This will ignore any unknown fields that are silently dropped from the object, and will ignore all but the last duplicate field that the decoder encounters. This is the default behavior prior to v1.23. - Warn: This will send a warning via the standard warning response header for each unknown field that is dropped from the object, and for each duplicate field that is encountered. The request will still succeed if there are no other errors, and will only persist the last of any duplicate fields. This is the default in v1.23+ - Strict: This will fail the request with a BadRequest error if any unknown fields would be dropped from the object, or if any duplicate fields are present. The error returned from the server will contain all unknown and duplicate fields encountered.', 'name': 'fieldValidation', 'in': 'query'}), OpenAPI20Parameter(definition={'uniqueItems': True, 'type': 'boolean', 'description': 'Force is going to "force" Apply requests. It means user will re-acquire conflicting fields owned by other people. Force flag must be unset for non-apply patch requests.', 'name': 'force', 'in': 'query'}), OpenAPI20Parameter(definition={'uniqueItems': True, 'type': 'string', 'description': "If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget).", 'name': 'pretty', 'in': 'query'})]), body=PayloadAlternatives(items=[OpenAPI20Body(definition={'name': 'body', 'in': 'body', 'required': True, 'schema': {'type': 'object'}}, media_type='application/json-patch+json'), OpenAPI20Body(definition={'name': 'body', 'in': 'body', 'required': True, 'schema': {'type': 'object'}}, media_type='application/merge-patch+json'), OpenAPI20Body(definition={'name': 'body', 'in': 'body', 'required': True, 'schema': {'type': 'object'}}, media_type='application/apply-patch+yaml')]), case_cls=<class 'schemathesis.models.Case'>), generation_config=GenerationConfig(allow_x00=True, codec='utf-8', headers=HeaderConfig(strategy=None)), headers={}, skip_on_not_negated=False)

Expected behavior

No crashes

Environment

- OS: Linux
- Python version: 3.12
- Schemathesis version: 3.29.2
- Spec version: Open API 2

Additional context

@vrutkovs vrutkovs added Status: Needs Triage Requires initial assessment to categorize and prioritize Type: Bug Errors or unexpected behavior labels Jun 18, 2024
@Stranger6667
Copy link
Member

Hi @vrutkovs

Thank you so much for reporting! :) I think it is related to the recent changes in Hypothesis, originally I was assuming it was a thread-safety issue, but as far as I see, you don't use the "-w" CLI option, right?

@vrutkovs
Copy link
Author

vrutkovs commented Jun 18, 2024

I have -w 10 set, all params are:

  --show-trace \
  --request-cert /kube_configs/clientCert.pem \
  --request-cert-key /kube_configs/clientKey.pem \
  --request-tls-verify false \
  --junit-xml /results/junit.xml \
  --workers 10 \
  --checks not_a_server_error \
  --report \
  --request-timeout 500 \

Testing if --worker 1 makes a difference.

UPD: Right, its parallelism. Can't make it crash with -w 1

@Stranger6667
Copy link
Member

I'll submit a fix upstream - a shared cache causes it, but usually such caches are thread-local in Hypothesis.

@Stranger6667 Stranger6667 added Priority: High Important but not urgent and removed Status: Needs Triage Requires initial assessment to categorize and prioritize labels Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High Important but not urgent Type: Bug Errors or unexpected behavior
Projects
None yet
Development

No branches or pull requests

2 participants