Skip to content

bug: Jinja2 Computed Attribute Error #7836

@minitriga

Description

@minitriga

Component

No response

Infrahub version

1.6.0

Current Behavior

When using infrahub version 1.4.13 with the following schema attributes the result of the jinja2 template is TEST000000100

      - name: number_sequence
        kind: NumberPool
        read_only: true
        optional: false
        parameters:
          start_range: 100
          end_range: 999999999
      - name: number
        kind: Text
        read_only: true
        optional: false
        computed_attribute:
          kind: Jinja2
          jinja2_template: "TEST{{ '%09d' | format(number_sequence__value) }}"

However after upgrading to 1.6.0 this jinja template breaks with infrahub giving the following error:
%d format: a real number is required, not NoneType

Expected Behavior

I would expect the jinja2 template to not be impacted between versions.

Steps to Reproduce

Load the following schema on 1.4.13

---
version: "1.0"
nodes:
  - name: Test
    namespace: Test
    description: "TestTest"
    label: "TEST"
    icon: "mdi:hub"
    display_labels: 
      - name__value
    human_friendly_id: []
    uniqueness_constraints: []
    attributes:
      # custom fields
      - name: name
        kind: Text
        unique: false
      - name: description
        kind: TextArea
        optional: true

      # auto-populated fields
      - name: number_sequence
        kind: NumberPool
        read_only: true
        optional: false
        parameters:
          start_range: 100
          end_range: 999999999
      - name: number
        kind: Text
        read_only: true
        optional: false
        computed_attribute:
          kind: Jinja2
          jinja2_template: "TEST{{ '%09d' | format(number_sequence__value) }}"

adding a new test should work.

load the same schema on 1.6.0 and creating a node should fail.

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    group/backendIssue related to the backend (API Server, Git Agent)type/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