fix: add support for schemas that don't have a name attribute#75
Open
fix: add support for schemas that don't have a name attribute#75
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
schould be merged after #74
When you used
nornir_infrahubfor 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.