Skip to content

Approvals Api does not work with replacing rules #11

Open
@chrisdurand-RL

Description

@chrisdurand-RL

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions