1010if TYPE_CHECKING :
1111 from collections .abc import Generator , Iterable , Mapping
1212
13+ from ..metadata import _ALL_FIELDS
14+
1315__all__ = ["load_dynamic_metadata" , "load_provider" ]
1416
1517
@@ -80,6 +82,9 @@ def _load_dynamic_metadata(
8082]:
8183 for field , orig_config in metadata .items ():
8284 if "provider" in orig_config :
85+ if field not in _ALL_FIELDS :
86+ msg = f"{ field } is not a valid field"
87+ raise KeyError (msg )
8388 config = dict (orig_config )
8489 provider = config .pop ("provider" )
8590 provider_path = config .pop ("provider-path" , None )
@@ -89,6 +94,9 @@ def _load_dynamic_metadata(
8994 if isinstance (loaded_provider , DynamicMetadataNeeds )
9095 else []
9196 )
97+ if needs > _ALL_FIELDS :
98+ msg = f"Invalid dyanmic_metada_needs: { needs - _ALL_FIELDS } "
99+ raise KeyError (msg )
92100 yield field , loaded_provider , config , needs
93101 else :
94102 yield field , None , dict (orig_config ), frozenset ()
@@ -98,6 +106,10 @@ def load_dynamic_metadata(
98106 metadata : Mapping [str , Mapping [str , str ]],
99107) -> list [tuple [str , DMProtocols | None , dict [str , str ]]]:
100108 initial = {f : (p , c , n ) for (f , p , c , n ) in _load_dynamic_metadata (metadata )}
101- sorter = TopologicalSorter ({f : n for f , (_ , _ , n ) in initial .items ()})
109+
110+ dynamic_field = initial .keys ()
111+ sorter = TopologicalSorter (
112+ {f : n & dynamic_field for f , (_ , _ , n ) in initial .items ()}
113+ )
102114 order = sorter .static_order ()
103115 return [(f , * initial [f ][:2 ]) for f in order ]
0 commit comments