Skip to content

fix: add support for schemas that don't have a name attribute#75

Open
wvandeun wants to merge 2 commits intostablefrom
fix-custom-name-attribute
Open

fix: add support for schemas that don't have a name attribute#75
wvandeun wants to merge 2 commits intostablefrom
fix-custom-name-attribute

Conversation

@wvandeun
Copy link
Copy Markdown
Contributor

@wvandeun wvandeun commented Apr 23, 2026

schould be merged after #74

When you used nornir_infrahub for a schema node, that doesn't define a name attribute in the schema, then the inventory would fail to load.

This fix allows you to define another attribute that can be mapped to a Nornir's host name property.

The default behavior is unchanged, if no name property mapping is provided, we will try to retrieve the value of the name attribute.

Resolving a schema_mapping like `primary_address.address` raised
`AttributeError: 'NoneType' object has no attribute 'ip'` because the
SDK store was returning a stub peer with `address.value = None`.

Root cause: the inventory pre-fetched every related kind separately with
`populate_store=True`, then fetched host nodes — also with
`populate_store=True`. The host fetch returned each relation peer as a
minimal stub (id/typename only) and overwrote the fully-hydrated peer
that had just been cached. `resolve_node_mapping` then walked
`<relation>.peer` into the stub and read `None`.

Replace the two-phase fetch with a single host-node fetch that uses
`include=` to hydrate exactly the relations referenced by the
schema_mappings and group_mappings. Drop `get_related_nodes`, the
`extra_nodes` attribute, and the pre-fetch loop.

`include=` on the SDK is strictly one-hop, so reject multi-hop
mappings and mappings that reference a name that is not a
relationship on the host kind, both with clear errors at init time.
@wvandeun wvandeun requested a review from a team as a code owner April 23, 2026 21:15
@BeArchiTek BeArchiTek changed the title fix: add suppor for schemas that don't have a name attribute fix: add support for schemas that don't have a name attribute Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant