launchdarkly / api-client-python

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

Approvals Api does not work with replacing rules #11

Open chrisdurand-RL opened 2 years ago

chrisdurand-RL commented 2 years ago

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'
carmenquan commented 2 years ago

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

tonyurso-RL commented 2 years ago

Hi there,

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

carmenquan commented 2 years ago

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.

tonyurso-RL commented 2 years ago

Can you recommend any workarounds at the moment?

On Thu, May 12, 2022, 5:51 PM carmenquan @.***> wrote:

Hi @tonyurso-RL https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/launchdarkly/api-client-python/issues/11#issuecomment-1125553299, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQKF3LPTXIXBWSALGMXYQXTVJWRR7ANCNFSM5VWUDMKA . You are receiving this because you were mentioned.Message ID: @.***>

carmenquan commented 2 years ago

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.

chrisdurand-RL commented 2 years ago

Hello, do you have any updates for this bug?

Selina-LD commented 2 years ago

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