launchdarkly / api-client-python

LaunchDarkly API Client for Python
Other
5 stars 8 forks source link

Cannot use semantic patches for patch_feature_flag despite support from the underlying API #9

Closed chrisdurand-RL closed 2 years ago

chrisdurand-RL commented 2 years ago

I am trying to do a workflow that requires either changing a flag directly or creating a change request, depending on the permission level of the user. This would be far easier if I could represent them the same way for each API. As the Approval API only accepts semantic patches, and not JSON patches, it made sense to try and use the functionality specified here to use the patch_feature_flag endpoint with semantic patches.

There is no way to add a set of instructions to the patch_feature_flag method in the API client, but I can still set the header value Content-Type in such a way that the actual API will reject my request.

Steps to reproduce:

  1. Create a service token with write privileges to your project
  2. Create a project with the key "project"
  3. Create a flag called "TEST_FLAG"
  4. Create an environment called "test"

The code below does not work using the semantic patch domain model, but works without it.

configuration = launchdarkly_api.Configuration()
configuration.api_key["ApiKey"] = api_key
api_client = launchdarkly_api.ApiClient(
    configuration,
    # Comment out the line below to use the normal domain model of json patch
    header_name="Content-Type", header_value="application/json; domain-model=launchdarkly.semanticpatch"
)
ff_client = feature_flags_api.FeatureFlagsApi(api_client)
rules = [
    Rule(
        clauses=[
            Clause(attribute="service", negate=False, op="in", values=['fake-service']),
        ],
        variation=0,
        track_events=False,
    )
]
patch = JSONPatch([
    PatchOperation(
        op="replace",
        path=f"/environments/test/rules",
        value=rules,
    )
])
ff_client.patch_feature_flag('project', 'TEST_FLAG', patch)
carmenquan commented 2 years ago

Hi @chrisdurand-RL, thanks for reaching out! Our client library only supports JSON Patch for this endpoint. I recognize we have room for improvement both for how we document which endpoint supports JSON patch vs semantic patch and also consistency across patch endpoints. Please know that we are tracking both these improvements internally and appreciate your feedback.