launchdarkly/api-client-python

Approvals Api does not work with replacing rules

Opened this issue · 7 comments

When doing a rule replacement, the semantic patch expects the field variationId to be present. However, the internal model for Rule has a property variation. These are incompatible and the service throws an error.

import launchdarkly_api
from launchdarkly_api.api import  approvals_api

configuration = launchdarkly_api.Configuration()
configuration.api_key["ApiKey"] = API_KEY
api_client = launchdarkly_api.ApiClient(configuration)
approvals_client = approvals_api.ApprovalsApi(api_client)

rules = [
    Rule(
        clauses=[
            Clause(attribute="service", negate=False, op="in", values=['fake-service']),
        ],
        variation=0,
        track_events=False,
    )
]

approval_request = CreateFlagConfigApprovalRequestRequest(
    comment="comment",
    description="description",
    instructions=Instructions([
        Instruction(
            kind="replaceRules",
            rules=rules
        ),
    ]),
    notify_member_ids=['my_id_number']
)

approvals_client.post_approval_request('project', 'TEST_FLAG', 'test', approval_request)
{"code":"invalid_request","message":"rule index 0: instruction variationId or rolloutWeights must be specified"}

As you can see from the model for Rule, the attribute is called variation, not variationId.
I can try to use a raw dictionary that conforms to the semantic patch pattern, but then I get a different error:

configuration = launchdarkly_api.Configuration()
configuration.api_key["ApiKey"] = API_KEY
api_client = launchdarkly_api.ApiClient(configuration)
approvals_client = approvals_api.ApprovalsApi(api_client)

rules = [
    Rule(
        clauses=[
            Clause(attribute="service", negate=False, op="in", values=['fake-service']),
        ],
        variation=0,
        track_events=False,
    )
]

approval_request = CreateFlagConfigApprovalRequestRequest(
    comment="comment",
    description="description",
    instructions=Instructions([
        Instruction(
            kind="replaceRules",
            rules=[
                {
                    "variationId": 1,
                    "clauses":  [
                        {
                            "attribute": "service",
                            "op": "in",
                            "negate": False,
                            "values": ["fake-service"]
                        }
                    ],
                }
            ]
        ),
    ]),
    notify_member_ids=['my-member-id']
)

approvals_client.post_approval_request('project', 'TEST_FLAG', 'test', approval_request)
AttributeError: 'dict' object has no attribute '_composed_schemas'

Thanks again @chrisdurand-RL - I'm following up with my team and will get back to you with a timeline for a fix.

Hi there,

Any update here? Our launch is currently blocked on this issue. Who can we reach out to can an update?

Hi @tonyurso-RL, we are actively investigating the issues and working towards a new release with all the identified fixes. I'll update when we have a clear timeline to provide.

Hi @tonyurso-RL,

The correct way to populate instructions for this request is using the raw dictionary, not using the model for Rule directly. However, the error you are seeing when you do that is related to the open-source openapi generator that we rely on to generate our client library, and we're currently investigating. Unfortunately I don't have a workaround other than making a request without our client library to unblock yourself, but we are actively working to get a new release out.

Hello, do you have any updates for this bug?

Hey Chris, just sent you an email with an update.