Forum Discussion
call function in user data functions
- 9 months ago
use this code (tested & working):
import datetime import fabric.functions as fn import logging udf = fn.UserDataFunctions() async def get_environment_local(varLib: fn.FabricVariablesClient) -> str: variables = varLib.getVariables() # sync call return variables["omgeving"] async def get_result_local(varLib: fn.FabricVariablesClient) -> str: return await get_environment_local(varLib) @udf.connection(argName="varLib", alias="varlib") @udf.function() async def hello_fabric(name: str, varLib: fn.FabricVariablesClient) -> str: logging.info("Running hello_fabric") omgeving = await get_result_local(varLib) return ( f"Welcome to Fabric Functions, {name}. " f"Omgeving: {omgeving}. " f"Time: {datetime.datetime.now()}" )
When a function has @udf.function(), it becomes a remote Fabric function, not a normal Python function. Calling it directly (await get_environment(varLib)) bypasses Fabric's runtime, so the injected connection becomes None, and Fabric later tries to access None.headers, causing the NoneType error. Make helper functions local (not decorated) so they behave like real Python functions.
Therefore I modified the code to remove the @udf.function() decorators from the helper functions and turn them into normal local Python functions, so they no longer get wrapped by the Fabric runtime and can be safely called from inside the main UDF with a valid varLib connection.
Hi OnurOz
I've try your solution, but it don't work, i got the error message:
AttributeError: 'NoneType' object has no attribute 'headers'
I think the problem is in the call function without VarLib parameter: get_environment()