Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
I'm working in a Microsoft Fabric workspace and using a user-defined function (UDF) to query a Fabric SQL database and return results as a pandas DataFrame. The function is defined as follows:
import pandas as pd
import fabric.functions as fn
udf = fn.UserDataFunctions()
@udf.connection(argName="sqlDB", alias="RAMSES2010dbMIRROR")
@udf.function()
def read_from_sql_db(sqlDB: fn.FabricSqlConnection, query: str) -> pd.DataFrame:
connection = sqlDB.connect()
df = pd.read_sql(query, connection)
return df This works fine for most queries where I am getting string and numbers.
However, when I attempt to cast date fields using either CAST() or TRY_CAST() in my SQL query, the function fails with the following error:
{
"functionName": "read_from_sql_db",
"invocationId": "00000000-0000-0000-0000-000000000000",
"status": "Failed",
"errors": [
{
"errorCode": "WorkloadException",
"subErrorCode": "InternalServerError",
"message": "User data function: 'read_from_sql_db' invocation failed."
}
]
}I have tried two methods to cast the date.
SELECT CAST([Expiration Date] AS DATE) AS [Expiration Date] FROM [dbo].[vw_LeaseActivationReport]SELECT TRY_CAST([Expiration Date] AS DATE) AS [Expiration Date] FROM [dbo].[vw_LeaseActivationReport]
Running the same query directly in the SQL endpoint works fine and returns valid dates.
When using the UDF, the date columns are either blank or replaced with {} in the resulting DataFrame.
Is this a known issue with the Fabric Platform?
How can I get this to work correctly?
Environment:
Workspace: Microsoft Fabric
SQL Source: Fabric SQL Mirror Database ()
UDF Framework: fabric.functions.UserDataFunctions
Python Runtime: Fabric Notebook
Connector: sqlDB.connect() via FabricSqlConnection
Solved! Go to Solution.
Hello @abhidotnet,
Thank you for reaching out to the Microsoft Fabric Community Forum. The issue with casting dates in your UDF likely stems from how the Fabric SQL connector handles DATE types when converting to a pandas DataFrame. Since the query works in the SQL endpoint, try these workarounds:
If you have any further questions, please don't hesitate to contact us through the community. We are happy to assist you.
Best Regards,
Ganesh Singamshetty.
This worked for me.
Hello @abhidotnet,
Thank you for reaching out to the Microsoft Fabric Community Forum. The issue with casting dates in your UDF likely stems from how the Fabric SQL connector handles DATE types when converting to a pandas DataFrame. Since the query works in the SQL endpoint, try these workarounds:
If you have any further questions, please don't hesitate to contact us through the community. We are happy to assist you.
Best Regards,
Ganesh Singamshetty.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!