Forum Discussion

bruinsmm's avatar
bruinsmm
Frequent Visitor
8 months ago
Solved

Parameters FabricVariablesClient and FabricLakehouseClient in one udf function

When i use one UDF function with 2 parameters:  myLakehouseDEV: fn.FabricLakehouseClient and var: fn.FabricVariablesClient i got and error, see below. When i use 2 UDF functions, one for FabricLakehouseClient and one for FabricVariablesClient, it works. Why can i not combine these parameters? A bug ?

 

 

Error message:

{

  "functionName": "query_data",

  "invocationId": "00000000-0000-0000-0000-000000000000",

  "status": "Failed",

  "errors": [

    {

      "errorCode": "WorkloadException",

      "subErrorCode": "InternalServerError",

      "message": "An internal execution error occured"

    }

  ]

}

 

Source code:

 

@udf.connection(argName="myLakehouseTEST", alias="lhbronzesharedDEV")

@udf.connection(argName="var", alias="varlib")

@udf.function()

def query_data(myLakehouseTEST: fn.FabricLakehouseClient, var: fn.FabricVariablesClient) -> list:

 

    connection = myLakehouseTEST.connectToSql()

   

    cursor = connection.cursor()

    cursor.execute(f"SELECT NAAM_NL, NAAM_EN FROM MDR.LAND WHERE LAND_ID = 142;")

   

    rows = [x for x in cursor]

    columnNames = [x[0] for x in cursor.description]

   

    values = []

    for row in rows:

        item = {}

        for prop, val in zip(columnNames, row):

            item[prop] = val

        values.append(item)

 

    # Close the connection

    cursor.close()

    connection.close()

 

    return values

  • bruinsmm  Mauro89 

    Thanks OnurOz for the code. I had contact with someone from Microsoft team today and today the code worked in my tenant and theirs. So the issue seems fixed and it should now work in your environment.

     

12 Replies

  • bruinsmm  Mauro89 

    Thanks OnurOz for the code. I had contact with someone from Microsoft team today and today the code worked in my tenant and theirs. So the issue seems fixed and it should now work in your environment.

     

  • OnurOz's avatar
    OnurOz
    Resolver III

    Hi bruinsmm 

     

    this looks to me like an undocumented runtime limitation or a bug. Because I am getting the same error too.
    However, in official github repository for the UDFs, I saw an example that requires that this works:

    fabric-user-data-functions-samples/PYTHON/Warehouse/export_warehouse_data_to_lakehouse.py at main ยท microsoft/fabric-user-data-functions-samples

     

    In the example above, I see two connections injected.

     

    I suggest filing a bug to the team using this link: https://github.com/microsoft/fabric-user-data-functions-samples/issues

     

    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.


    • OnurOz's avatar
      OnurOz
      Resolver III

      I've dug more into this and identified a very weird behaviour. If I use FabricSQLConnection together with the FabricLakehouseClient it works. However If I use the FabricVariablesClient together with any of them, that is not working and throwing exactly the same internal error.

       

      import fabric.functions as fn
      
      udf = fn.UserDataFunctions()
      
      
      @udf.connection(argName="variables", alias="varlib")
      @udf.function()
      def this_works(variables: fn.FabricVariablesClient )-> str:    
          return variables.getVariables()["x"]
      
      
      @udf.connection(argName="variables", alias="varlib")
      @udf.connection(argName="myWarehouse", alias="fabWH")
      @udf.function()
      def this_fails(variables: fn.FabricVariablesClient, myWarehouse: fn.FabricSqlConnection, )-> str:    
          return variables.getVariables()["x"]
      
      
      @udf.connection(argName="variables", alias="varlib")
      @udf.connection(argName="myLakehouse", alias="fablakehouse")
      @udf.function()
      def this_fails_too(variables: fn.FabricVariablesClient, myLakehouse: fn.FabricLakehouseClient, )-> str:    
          return variables.getVariables()["x"]
      
      






      • nielsvdc's avatar
        nielsvdc
        Super User

        Hi OnurOz, it looks like this is unwanted behavior. Are you able to create a support request at Microsoft for this? I can also offer to help do this.

  • Hi bruinsmm,

     

    have you used the defined aliases and checked if both connections are actually there?

     

    Best regards!

    • bruinsmm's avatar
      bruinsmm
      Frequent Visitor

      Hi Mauro89 ,

      If i use one function with FabricLakehouseClient and one function with FabricVariablesClient, it works. so the aliases are set up correctly.