Hadron / carthage

Carthage is an Infrastructure as Code (IAC) framework
Other
7 stars 4 forks source link

if full_key in ConfigSchema._schemas: will always evaluate False for sub-keys #9

Closed srak289 closed 2 years ago

srak289 commented 2 years ago

layout.py : 28 During construction of schema items in the layout._load() function full_key is only checked against ConfigSchema._schemas. This will always evaluate to False for sub-keys in the config file.

(Pdb) 'access_key_id' in ConfigSchema._schemas
False
(Pdb) 'access_key_id' in ConfigSchema._schemas['aws']
True

This may be inconsequential but I believe it is a bug.

hartmans commented 2 years ago
> layout.py : 28 During construction of schema items in the
> `layout._load()` function `full_key` is only checked against
> `ConfigSchema._schemas`.  This will always evaluate to `False` for
> sub-keys in the config file.

For leaf keys, yes this will be false. But the intent of that check is to figure out whether we are loading something that has a prefix. Consider

class Schema(ConfigSchema, prefix="foo.bar.baz"): pass

Then foo.bar.baz will be in ConfigSchema._schemas. It's not subkeys in config files we're check for, but rather to see if there is a registered schema. Because if there is, we want to require a dict from the file we're loading.

Do you still think this is a bug?

srak289 commented 2 years ago

Ah, that makes sense.

No, it does not seem like a bug with that additional perspective.