Skip to content

bug: Read-only attributes (i.e computed_attribute) are part of the schema.mandatory_input_name #268

Closed
@BeArchiTek

Description

@BeArchiTek

Component

No response

Infrahub SDK version

1.7.1

Current Behavior

In our SDK, we have some functions

def attribute_names(self) -> list[str]:

    @property
    def attribute_names(self) -> list[str]:
        return [item.name for item in self.attributes]

    @property
    def relationship_names(self) -> list[str]:
        return [item.name for item in self.relationships]

    @property
    def mandatory_input_names(self) -> list[str]:
        return self.mandatory_attribute_names + self.mandatory_relationship_names

    @property
    def mandatory_attribute_names(self) -> list[str]:
        return [item.name for item in self.attributes if not item.optional and item.default_value is None]

    @property
    def mandatory_relationship_names(self) -> list[str]:
        return [item.name for item in self.relationships if not item.optional]

Those verified if a given attribute is optional and if there is a default_value, but not if the attribute is read_only.

Expected Behavior

I would expect the read_only attribute to not be return as part of the "mandatory_input_names"

Steps to Reproduce

Using the demo-schema and demo-data
Run the script below :

from infrahub_sdk import InfrahubClient, Config
client = InfrahubClient(address="http://localhost:8000", config=Config(api_token="06438eb2-8019-4776-878c-0941b1f1d1ec",timeout=240,default_branch="main"),)

schema = await client.schema.get(kind="InfraDevice")

schema.mandatory_input_names

you should see

['computed_description', 'type', 'name', 'site']

With computed_description being a computed_attribute, mandatory based on a jinja2

AttributeSchemaAPI(id='18219d74-9f39-653e-2db1-c512aa060fe0', state='present', name='computed_description', kind='Text', label='Computed Description', description='Combine various attributes to provide a human frendly description of this device.', default_value=None, unique=False, branch='aware', optional=False, choices=None, enum=None, max_length=None, min_length=None, regex=None, order_weight=3000, inherited=False, read_only=True, allow_override='any'),

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/2This issue stalls work on the project or its dependents, it's a blocker for a releasetype/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions