Closed poleshe closed 2 years ago
Hi @poleshe, thank you for raising this - it is up to the app to check if the input is available before using it - what App specifically are you referencing?
Hi!
Not really a public App as we develop our custom Apps.
True, the app must check the input before using it, I just think it's weird that the input is not instatiated at all if the optional input is not passed, as it messes with compatbility with integrations developed in older versions and feels weird.
Maybe it's expected! Just wanted to ask.
Thanks again,
Hey @poleshe,
So if the older App's Functions are continuing to use the ResilientComponent
class - the inputs should not be affected and are accessed via **kwargs
.
Whereas in the new AppFunctionComponent
class, the methods in that class use the @app_function
handler, these methods have fn_inputs
as a parameter which is a Python NamedTuple: https://docs.python.org/3.9/library/collections.html?highlight=namedtuple#collections.namedtuple - initially this was thought to be easier to develop with as you can access its attributes using dot notation - its seeming not to be the case, we may redesign the logic internally, but no promises!
Really appreciate you raising as an issue and we will take the feedback and see what we can produce 🤞
Greetings @sj-curtin
I think I've explained myself wrong! The NamedTuples is an upgrade over kwargs, much easier to use and interact. I wouldn't want to go back :P
The "issue" here is, that given:
fn_inputs.obligatoryinput
fn_inputs.optionalinput
# If we try to use fn_inputs.optionalinput, but the input has no value, we find:
AttributeError: 'fn_inputs' object has no attribute 'optionalinput'
The documentation generated with the jinja template states that we should validate these inputs using hasattr, I was just wondering why arent they just initialized as None
.
# Example accessing optional attribute in fn_inputs (this is similar for app_configs)
# optional_input = fn_inputs.optional_input if hasattr(fn_inputs, "optional_input") else "Default Value"
Have a nice day!
Description
Greetings!
When an optional input is not given a value in a workflow, it is not instantiated in the function. I think this is expected as it is referenced in the jinja template documentation, buy, why is not instantiated with a None by default? In older resilient versions, when the inputs were retrieved with kwargs, they were instantiated, but empty.
If it is not wanted to be used in the function, it should be removed from the function directly.
Thanks for your time! And for your response!
Describe How to Reproduce
Kind regards,