pact-foundation / pact_broker

Enables your consumer driven contracts workflow
http://pactflow.io
MIT License
705 stars 173 forks source link

Release 2.105.0 allow_dangerous_contract_modification not respected when set via accessor #582

Open sbarrypoppulo opened 1 year ago

sbarrypoppulo commented 1 year ago

Pre issue-raising checklist

I have already (please mark the applicable with an x):

Software versions

Expected behaviour

When allow_dangerous_contract_modification is set via accessor for an existing installation publishing pact should not fail with HTTP 409

2022-11-22 10:11:31.678638 I [8:4400] pact-broker -- PACT BROKER CONFIGURATION:
2022-11-22 10:11:31.679094 I [8:4400] pact-broker -- allow_dangerous_contract_modification=true source={:type=>:accessor, :called_from=>"/pact_broker/vendor/bundle/ruby/2.7.0/gems/pact_broker-2.105.0/lib/pact_broker/config/load.rb:45"}
Publishing '<PACT>.json' with tags 'wip' ... 
Failed - Request to path 'https://<PACT_BROKER_URL>/contracts/publish' failed with response 409
{"notices":[{"type":"error","text":"Cannot change the content of the pact for <PACT> version <VERSION> and provider <PROVIDER< as race conditions will cause unreliable results for can-i-deploy. Each pact must be published with a unique consumer version number. For more information see https://docs.pact.io/go/versioning"},{"type":"info","text":"     {\n       \"response\": {\n         \"headers\": {\n-          \"Content-Type\": \"application/json;charset=UTF-8\"\n+          \"Content-Type\": \"application/json;charset=utf-8\"\n         }\n       }\n     },"}],"errors":{"contracts":["Cannot change the content of the pact for <PACT> version <VERSION> and provider <PROVIDER>, as race conditions will cause unreliable results for can-i-deploy. Each pact must be published with a unique consumer version number. For more information see https://docs.pact.io/go/versioning"]}}

Actual behaviour

I had to explicitly set environment variable PACT_BROKER_ALLOW_DANGEROUS_CONTRACT_MODIFICATION to true in order to successfully publish the pact. This contradicts the behaviour described for existing installations here

2022-11-23 09:53:44.165562 I [8:4400] pact-broker -- PACT BROKER CONFIGURATION:
2022-11-23 09:53:44.165911 I [8:4400] pact-broker -- allow_dangerous_contract_modification=true source={:type=>:env, :key=>"PACT_BROKER_ALLOW_DANGEROUS_CONTRACT_MODIFICATION"}
Publishing '<PACT>.json' with tags 'wip' ... 
OK

Steps to reproduce

  1. Update to 2.105.0 and confirm that allow_dangerous_contract_modification=true in pact broker configuration (set via accessor)
  2. Publish a pact for an existing version
  3. Observe HTTP 409 error
  4. Explicitly set PACT_BROKER_ALLOW_DANGEROUS_CONTRACT_MODIFICATION=true and deploy change
  5. Confirm that allow_dangerous_contract_modification=true in pact broker configuration (set via env var)
  6. Publish a pact for an existing version
  7. Pact is successfully published

Provide a repository, gist or reproducible code snippet so that we can test the problem.

Relevant log files

Please ensure you set logging to DEBUG and attach any relevant log files here (or link from a gist).

Configuration sample logs and pact publishing snippets provided (w/ redaction)

bethesque commented 1 year ago

Thanks for the detailed report. I don't know when I will be able to look into this. I'm glad to see you have found a workaround.

Can you explain more about your scenario? Do you understand why the feature was implemented, and what effect changing the already existing pacts will have on your pipeline? Can I suggest that you work on updating your pipeline so that the pact does not change once published?