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

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

Open
BeArchiTek opened this issue Feb 11, 2025 · 3 comments
Labels
priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release type/bug Something isn't working as expected

Comments

@BeArchiTek
Copy link
Contributor

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

@BeArchiTek BeArchiTek added the type/bug Something isn't working as expected label Feb 11, 2025
@ogenstad
Copy link
Contributor

Computed attributes that are mandatory would be for those defined to use a Jinja2 template where all information required can be accessed from other fields. These can still not be updated from the SDK though, but the SDK should not complain if you try to create a node with a required computed attribute.

@BeArchiTek
Copy link
Contributor Author

From my point of view, a Read-Only attribute should not be part of "mandatory_input_names" as they are not "input"

It's as well to help the other tools to retrieve this and use it to create a "form" for the required input field (i.e service catalog)

@ogenstad
Copy link
Contributor

Sure I was just giving context why they are marked as mandatory within the schema, but they'd need to be excluded from this list.

@exalate-issue-sync exalate-issue-sync bot added the priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release type/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

2 participants