-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Component
infrahubctl
Infrahub SDK version
1.14.0
Current Behavior
This was originally reported in opsmill/infrahub#7265, as it's a bug related to the SDK it has been reopened here instead.
Address: http://localhost:8000
Connection Status: ✅
Python Version: 3.12.2
SDK Version: 1.14.0
Infrahub Version: 1.4.8
User: Admin
Issue:
version: "1.0"
nodes:
- name: Device
namespace: NGC
human_friendly_id: ['hostname__value']
attributes:
- name: hostname
kind: Text
unique: true
- name: model
kind: Text
According to the REGEX in the error message below, the namespace name above should be valid.
In the code, the regex that is actually used to validate the namespace is different from the one in the error message. The documentation (that I could find) does not describe what a valid schema name looks like.
This schema name is invalid
/infrahubctl schema load --branch demo2 schemas/test.yml
Unable to load the schema:
Node: NGCDEVICE | namespace (NGC) | String should match pattern '^[A-Z]+$' (string_pattern_mismatch)
Valid namespace names are currently are '^[A-Z][a-z]+$'
-
Block caps should be allowed for namespace names.
-
At a minimum, the error message should display the actual regex used to validate the namespace name, not an incompatible regex that will never be a valid schema name.
Expected Behavior
The regex in the error message should be the one used to validate the namespace name, not a random incompatible one.
Steps to Reproduce
See schema above and try to import it.
Additional Information
This seems to be coming from the rich library when we print out the error here: https://github.com/opsmill/infrahub-sdk-python/blob/v1.14.0/infrahub_sdk/ctl/schema.py#L76
Looks like rich is treating '^[A-Z][a-z0-9]+$' as invalid markup and strips out some parts.
The correct way would be to instead have:
console.print(f" Node: {node.get('namespace', None)}{node.get('name', None)} | {error_message}", markup=False)