@@ -46,30 +46,30 @@ def _set(self, node: InfrahubNode | InfrahubNodeSync | SchemaType, key: str | No
4646
4747 def _get (self , key : str , kind : str | type [SchemaType ] | None = None , raise_when_missing : bool = True ): # type: ignore[no-untyped-def]
4848 kind_name = get_schema_name (schema = kind )
49- if kind_name and kind_name not in self ._store and key not in self ._store [kind_name ]: # type: ignore[attr-defined]
49+ if kind_name :
50+ if kind_name in self ._store and key in self ._store [kind_name ]: # type: ignore[attr-defined]
51+ return self ._store [kind_name ][key ] # type: ignore[attr-defined]
52+ else :
53+ if not raise_when_missing :
54+ return None
55+ raise NodeNotFoundError (
56+ node_type = kind_name ,
57+ identifier = {"key" : [key ]},
58+ message = "Unable to find the node in the Store for the specified kind" ,
59+ )
60+ else :
61+ # If no kind is provided, search all kinds.
62+ for item in self ._store .values (): # type: ignore[attr-defined]
63+ if key in item :
64+ return item [key ]
5065 if not raise_when_missing :
5166 return None
5267 raise NodeNotFoundError (
53- node_type = kind_name ,
68+ node_type = "n/a" ,
5469 identifier = {"key" : [key ]},
55- message = "Unable to find the node in the Store " ,
70+ message = f "Unable to find the node { key !r } in the store " ,
5671 )
5772
58- if kind_name and kind_name in self ._store and key in self ._store [kind_name ]: # type: ignore[attr-defined]
59- return self ._store [kind_name ][key ] # type: ignore[attr-defined]
60-
61- for item in self ._store .values (): # type: ignore[attr-defined]
62- if key in item :
63- return item [key ]
64-
65- if not raise_when_missing :
66- return None
67- raise NodeNotFoundError (
68- node_type = "n/a" ,
69- identifier = {"key" : [key ]},
70- message = f"Unable to find the node { key !r} in the store" ,
71- )
72-
7373 def _get_by_hfid (self , key : str , raise_when_missing : bool = True ): # type: ignore[no-untyped-def]
7474 try :
7575 return self ._store_by_hfid [key ]
0 commit comments