Forum Discussion
call function in user data functions
i have the following code in user data functions:
when i call the function get_environment function via function get_result , i got the following message:
<coroutine object get_environment at 0x78c6d405c880>
how can i get the the right one result.
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.
7 Replies
- OnurOzResolver III
Hi bruinsmm
(Edited my reply to fix the code, due the error mentioned here)
To get the correct value, modify get_result so it awaits get_environment. In Python with async/await, this means:@udf.connection(argName="varLib", alias="varlib") @udf.function() async def get_environment(varLib: fn.FabricVariablesClient) -> str: variables = varLib.getVariables() omgeving = variables["omgeving"] return omgeving @udf.function() async def get_result() -> str: result = await get_environment(varLib) # <--- FIX return resultHope that helps
Onur
😊If this post helped you, feel free to give it some Kudos! 👍
✅And if it answered your question, please mark it as the accepted solution.
- bruinsmmFrequent Visitor
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()
@udf.connection(argName="varLib", alias="varlib")@udf.function()async def get_environment(varLib: fn.FabricVariablesClient) -> str:variables = varLib.getVariables()omgeving = variables["omgeving"]return omgeving@udf.function()async def get_result() -> str:result = await get_environment() # <-- await itreturn result