Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bruinsmm
Frequent Visitor

call function in user data functions

i have the following code in user data functions:

 

@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 = get_environment()
    return result

 

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.

1 ACCEPTED SOLUTION

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.

View solution in original post

7 REPLIES 7
OnurOz
Resolver III
Resolver 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 result

 

Hope 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.


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 it
    return result

sorry my bad, I've forgotten to add varlib to the call get_environment(), following code should do the work:

@udf.function()
@udf.connection(argName="varLib", alias="varlib")
async def get_environment(varLib: fn.FabricVariablesClient) -> str:
    variables = varLib.getVariables()
    return variables["omgeving"]


@udf.function()
@udf.connection(argName="varLib", alias="varlib")
async def get_result(varLib: fn.FabricVariablesClient) -> str:
    result = await get_environment(varLib)   # I've forgotten this
    return result

 

I have try the code. It don't work :☹️

got the same error message: "error_message": "'NoneType' object has no attribute 'headers'"

 

@udf.connection(argName="varLib", alias="varlib")
@udf.function()
async def get_environment(varLib: fn.FabricVariablesClient) -> str:
    variables = varLib.getVariables()
    return variables["omgeving"]


@udf.connection(argName="varLib", alias="varlib")
@udf.function()
async def get_result(varLib: fn.FabricVariablesClient) -> str:
    result = await get_environment(varLib)   # I've forgotten this
    return 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.

@OnurOz I have tried your code. It works!!. Thanks for your help and explanation about decorators.

Hi @bruinsmm

 

Yes, you will need to pass in a valid varLib object as a parameter to the get_environment call. 

 

If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution. 

If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.

Helpful resources

Announcements
December Fabric Update Carousel

Fabric Monthly Update - December 2025

Check out the December 2025 Fabric Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.