Slight cleanup in the initialization of attributes and relationships #355
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.
This PR cleans up the initialization code for setting attributes and relationships within InfrahubNode objects. The problem here is that we iterate over the names of
self._attributesand then we have to iterate theself._schema.attributesand assume that there will always be a match (the[0]part), we'll always have a match here but it looks a bit off. Theself._attributesproperty will also use the schema listing to find the names to the part is pretty much just redundant. The same thing is happening for the relationships.I started to think about this during the weekend when considering how we could remove the way nodes are dynamically generated each time we initialize a new node using the SDK. In short I think we should replace the current
setattr, calls togenerate_relationship_propertyandself.__class__ = type(f"{schema.kind}InfrahubNode", (self.__class__,), {})within the__init__()method and transition to using a custom__getattr__method where this is handled instead.