Open ramondepieri opened 1 month ago
I think if we do fix it, to preserve backwards compatibility we may need to check (map) both the states and the description, and only error if one is not found.
This has always been a long-standing bug in the pact-python message pact implementation. You will need to map providerStates to message handlers in Pact-python at the moment.
It is also present in the v3 pact examples.
The consumer side
These should be swapped.
pact.given("a request to read test.txt")
.expects_to_receive("test.txt exists")
to be
pact.given("test.txt exists")
.expects_to_receive("a request to read test.txt")
In the message provider, we are incorrectly using the provider state, instead of the description
in the message provider proxy, that is shown in the examples, it does not provide a mechanism to pass the message description
Those examples should be updated in V3 as well, to use the description, and not the provider state, for the handler mappings
I think this definitely needs to be changed in V3, and I'm surprised it accidentally made its way into the V3 examples... I need to check whether this was an oversight while adapting the existing example only, or whether this error exists in the library itself.
As for the situation in V2, I'm hesitant to 'fix' this. As much as it is confusing, this feature has been around for long enough that a fix now would result in breaking changes for a lot of people. I do think more warnings about this behaviour should added to the documentation.
I think one way to fix it with backwards compatibility, would be to lookup both the description (first) and fallback to the state names if no handler is found that matches the description. If it falls back, we could consider printing a warning so it won't be as surprising when they upgrade to V4.
Have you read the Contributing Guidelines on issues?
Prerequisites
pact-python
.Description
I am trying to create a message contract test, but something is going wrong:
According to tests, the problem is happening in reason of mapping is being made by provider state instead of description
Reproducible demo
No response
Steps to reproduce
Run the consumer:
Now run the provider:
This error will happens: RuntimeError: An error was raised while verifying the message. The response body is: {"detail":"No matched handler."}
Now change the message_providers, to use "Create contract" string instead of "An event of contract"
Note that now is working
Expected behavior
The mapping should use the description instead of provider state
Actual behavior
RuntimeError: An error was raised while verifying the message. The response body is: {"detail":"No matched handler."}
Your environment
No response
Self-service