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

JSONPatch for off_variation doesn't work, result unchanged #17

Open
GeosMeos opened this issue Mar 10, 2024 · 4 comments
Open

JSONPatch for off_variation doesn't work, result unchanged #17

GeosMeos opened this issue Mar 10, 2024 · 4 comments

Comments

@GeosMeos
Copy link

I'm trying to patch off_variation in a specific environment(test in this case)

The following doesn't work(Note that i've taken this example from auto generated examples:

patch_off_variation = PatchWithComment(
        patch=JSONPatch([
            PatchOperation(
                op="replace",
                path="/environments/test/off_variation",
                value=1,
            ),
        ]),
        comment=f"{project_key}-patch-off_variation",
    )
api_response = api_instance.patch_feature_flag(project_key, feature_flag_key, patch_off_variation)

This however works with other fields such as on or fallthrough.variation

I've tried int and str, expected an error but operation returns 200.

Version(from pip freeze)
launchdarkly-api @ git+https://github.com/launchdarkly/api-client-python.git@9bdc16d79381a1f03c8a51dd69323c80a13a286d

@tvarney13
Copy link
Member

Hi @GeosMeos thanks for creating an issue. I've identified a bug related to what you've posted here, and created a ticket to resolve it. The API should have thrown an error based on your provided path.

In case you weren't already aware, the correct path in your snippet should be /environments/test/offVariation - we camel-case fields in our JSON representations.

@GeosMeos
Copy link
Author

@tvarney13 i've assumed so as the API is pointing to offVariation but when I try to update it, an error is returned:
HTTP response body: {"code":"not_found","message":"Invalid resource identifier"}

here's the snippet:

patch_off_variation = PatchWithComment(
    patch=JSONPatch(
        [
            PatchOperation(
                op="replace",
                path="/environments/test/offVariation",
                value=prod_config["offVariation"],
            ),
        ]
    ),
    comment=f"{project_key}-patch-off_variation",
)
api_response = api_instance.patch_feature_flag(
            project_key, feature_flag_key, patch_off_variation
        )

@tvarney13
Copy link
Member

@GeosMeos So in this case I was actually wrong about the path, you were right before. Sorry about that, I usually support the APIs themselves not these client libraries.

I attempted a similar request on a test flag in Postman and it worked, so just to verify - you're seeing that the value for the offVariation in the test environment remains 0 after the patch?

Here's my test request (the offVariation was set to 1 beforehand):

image

@lucywyman
Copy link

Hmmm, I was successfully able to update the off variation with the following:

with launchdarkly_api.ApiClient(configuration) as api_client:
    api_instance = feature_flags_api.FeatureFlagsApi(api_client)
    project_key = "my-project"
    feature_flag_key = "new-flag"
    patch_off_variation = feature_flags_api.PatchWithComment(
        patch = JSONPatch([
            PatchOperation(
                op="replace",
                path="/environments/test/offVariation",
                value=1,
            ),
        ]),
        comment="patch-off_variation",
    )
    try:
        # Update feature flag
        api_response = api_instance.patch_feature_flag(project_key, feature_flag_key, patch_off_variation)
        pprint(api_response)
    except launchdarkly_api.ApiException as e:
        print("Exception when calling FeatureFlagsApi->patch_feature_flag: %s\n" % e)

Just to clarify, what you want to do is update the value of the flag when the flag is off? Printing the API response, this should be the value that you see updated:

{'environments':{
...
                  'test': {'archived': False,
...
                           'off_variation': 1,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants