Closed ghost closed 2 years ago
It would appear the get method in FallbackDict sets the default type to None but normally trying to access an attribute on a Python object which does not exist will result in an AttributeError. I think the behavior here deviates from what an experienced Python user would expect (an exception).
Edit: adding that I could probably fix this but it would be good to understand if the current state was chosen for a particular reason that perhaps isn't obvious.
I'm pro this change in the upcoming v2 - agree that the current behaviour deviates from what you'd expect. I believe I originally made the choice to replicate jinja2
which does the same (by default), but that was many years ago :)
I think the behaviour should change to match Python:
host.data.NOT_A_VAR
>>> raises AttributeError
host.data.get('NOT_A_VAR')
>>> None
host.data.get('NOT_A_VAR', default='different-default')
>>> 'different-default'
I agree with the proposed behavior change. This should not deviate from standard python behavior.
This is now live in v2 (and shows warnings in v1.7.!!).
Describe the bug
When a variable referenced like so
where the variable
host.data.tinkerbell_user_uid
does not exist (as in, I never declared the variable), it defaults toNone
. This results in an error like this:more verbose
I think that this behavior is not desirable. It should probably throw an exception or something. Not sure if you have a reason why don't do this.
To Reproduce
deploy.py
Run pyinfra
Expected behavior
When a
host.data.VAR
does not exist I think an exception should be thrownMeta
section of
pyinfra -vvv
cc: @jmpolom @storrgie