I'm trying to set multiple values in given namespa...
# libpact_ffi-users
v
I'm trying to set multiple values in given namespace for pact metadata but always only get the last value I set. I'm using
pact-python
, but it passes its arguments along to
lib.pactffi_with_pact_metadata(
. My example is this:
Copy code
pact.with_metadata('namespace', {'var_1': 'value_1', 'var_2': 'value_2'})
which breaks down into multiple calls as listed above, but the resulting pact file only contains:
Copy code
"metadata": {
    "namespace": {
      "var_2": "value_2"
    },
    ...
y
You will want to use the v2 function I think
pactffi_message_with_metadata_v2
Copy code
PactFfi::MessageConsumer.with_metadata_v2(message, "namespace",'{"var_1":"value_1","var_2":"value_2"}')
Copy code
"metadata": {
        "contentType": "application/json",
        "namespace": {
          "var_1": "value_1",
          "var_2": "value_2"
        }
      },
v
interesting... that's gonna require a change to the clients I think
y
I think the v2 func was introduced to allow for metadata matchers using the integration json format.
btw good work on getting your matchers first pass in and merged, I’ve got it on my list to take a look this week
v
It doesn't look like either
pact-js
or
pact-python
use the
v2
function. Guess I'll see about getting that added to those 🙂. Thanks for the info!
oh wait - this is for
pact_metadata
, not
message_metadata
y
Ahh right, I imagine that will be implemented in the same way as the message_metadata(v1) func was, and probably suffers the same fate. we won’t need the matchers here, but may want to process json payloads with nested keys
what are you trying to set out of interest? pact-python client lib values?
v
We have a number of different ways our services interact with one another, and I was hoping to use metadata to track that information. I could probably also do it with tags, but that significantly complicates the publishing process for services that have several different pacts. It felt easier to just use metadata since that gets written directly into the pact file itself.
I can still do it with metadata. It's just going to be a little clunky
y
I don’t think has enough args btw
Copy code
pact.with_metadata('namespace', {'var_1': 'value_1', 'var_2': 'value_2'})
Copy code
/**
 * Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version
 * Returns false if the interaction or Pact can't be modified (i.e. the mock server for it has already started)
 *
 * * `pact` - Handle to a Pact model
 * * `namespace` - the top level metadat key to set any key values on
 * * `name` - the key to set
 * * `value` - the value to set
 */
bool pactffi_with_pact_metadata(PactHandle pact,
                                const char *namespace_,
                                const char *name,
                                const char *value);
v
The python library breaks that dict down into individual calls to
pactffi_with_pact_metadata
so it really is:
Copy code
pactffi_with_pact_metadata('namespace', 'var_1', 'value_1')
pactffi_with_pact_metadata('namespace', 'var_2', 'value_2')
y
ahh yeah, it must be a bug, it is only picking up the last value, where the namespace is not unique
I bet it isn’t cloning the existing items at that namespace before writing the namespace
v
oh cool - thank you!