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: Infrahubctl protocols doesn't support all attribute kind #57

Closed
8 tasks done
BaptisteGi opened this issue Oct 4, 2024 · 3 comments
Closed
8 tasks done

bug: Infrahubctl protocols doesn't support all attribute kind #57

BaptisteGi opened this issue Oct 4, 2024 · 3 comments
Assignees
Labels
type/bug Something isn't working as expected

Comments

@BaptisteGi
Copy link
Contributor

BaptisteGi commented Oct 4, 2024

Component

Python SDK, infrahubctl

Infrahub SDK version

0.14

Current Behavior

When I try to generate protocols for my schema it fails if my schema contains node with attributes of certain kind.

Expected Behavior

I expect my command to pass and generate protocols

Steps to Reproduce

  • invoke demo.stop demo.destroy demo.build demo.start
  • load the following schema
version: "1.0"

nodes:
  - name: FullAttributesNode
    namespace: Example
    description: "Node with all possible attribute kinds"
    attributes:
      - name: identifier
        kind: ID
      - name: text_attribute
        kind: Text
      - name: text_area_attribute
        kind: TextArea
      - name: datetime_attribute
        kind: DateTime
      - name: email_attribute
        kind: Email
      - name: password_attribute
        kind: Password
      - name: hashed_password_attribute
        kind: HashedPassword
      - name: url_attribute
        kind: URL
      - name: file_attribute
        kind: File
      - name: mac_address_attribute
        kind: MacAddress
      - name: color_attribute
        kind: Color
      - name: number_attribute
        kind: Number
      - name: bandwidth_attribute
        kind: Bandwidth
      - name: ip_host_attribute
        kind: IPHost
      - name: ip_network_attribute
        kind: IPNetwork
      - name: boolean_attribute
        kind: Boolean
      - name: checkbox_attribute
        kind: Checkbox
      - name: list_attribute
        kind: List
      - name: json_attribute
        kind: JSON
      - name: any_attribute
        kind: Any
      - name: dropdown_attribute
        kind: Dropdown
        choices:
          - name: option_1
            label: Option 1
            color: "#7fbf7f"
          - name: option_2
            label: Option 2
            color: "#ffff7f"
  • Then run infrahubctl protocols

Additional Information

So far are not supported:

  • Bandwidth
  • Color
  • Checkbox
  • ID
  • Email
  • MacAddress
  • File
  • Any

Seems to be missing in this map: https://github.com/opsmill/infrahub-sdk-python/blob/develop/infrahub_sdk/code_generator.py#L71

This is the error returned by the command:

infrahub-py3.12➜  infrahub git:(develop) ✗ infrahubctl protocols --branch main                
Error: 'email'
Traceback (most recent call last):
  File "/Users/Baptiste/Workspaces/Infrahub/infrahub/python_sdk/infrahub_sdk/ctl/utils.py", line 89, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Baptiste/Workspaces/Infrahub/infrahub/python_sdk/infrahub_sdk/ctl/cli_commands.py", line 356, in protocols
    write_to_file(output_file, code_generator.render(sync=sync))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Baptiste/Workspaces/Infrahub/infrahub/python_sdk/infrahub_sdk/code_generator.py", line 53, in render
    return template.render(
           ^^^^^^^^^^^^^^^^
  File "/Users/Baptiste/Library/Caches/pypoetry/virtualenvs/infrahub-6p6-ZiP_-py3.12/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/Users/Baptiste/Library/Caches/pypoetry/virtualenvs/infrahub-6p6-ZiP_-py3.12/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 73, in top-level template code
  File "/Users/Baptiste/Workspaces/Infrahub/infrahub/python_sdk/infrahub_sdk/code_generator.py", line 90, in _jinja2_filter_render_attribute
    attribute_kind = attribute_kind_map
                     ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'email'
@BaptisteGi BaptisteGi added the type/bug Something isn't working as expected label Oct 4, 2024
@BaptisteGi
Copy link
Contributor Author

@dgarros if I extend the map following what's already in there is it going to work?

@dgarros
Copy link
Contributor

dgarros commented Oct 4, 2024

@BaptisteGi yes updating the map is the main part
in addition to the map, we might need to update the Jinja template as well to pre import all the new kind

@BaptisteGi BaptisteGi self-assigned this Oct 4, 2024
@BaptisteGi BaptisteGi linked a pull request Oct 11, 2024 that will close this issue
@lykinsbd lykinsbd added this to the Python SDK - 14.1 milestone Oct 21, 2024
@BaptisteGi
Copy link
Contributor Author

fixed here #90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants