<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic User Data Function coroutine object error in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/User-Data-Function-coroutine-object-error/m-p/4828518#M12382</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I've created a UDF component with &lt;EM&gt;get_element_schedules(token, workspace_id, jobType)&lt;/EM&gt; function. This function returns a dict object with the list of pipelines (jobType=Pipeline) and notebooks (jobType=Notebook) in the workspace_id and the schedules associated to each pipeline/notebook. This dict object is created as a result of some calls to fabric API.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def get_element_schedules(token: str, workspace_id: str, jobType: str) -&amp;gt; dict:
   [....]
   elements_response = requests.get(elements_url, headers=headers)
   elements_data = elements_response.json().get("value", [])
   [...]
   return {"result": result}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that I want to create get_pipelines_schedules(token, workspace_id) and&amp;nbsp;get_notebooks_schedules(token, workspace_id) function as:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def get_pipelines_schedules(token: str, workspace_id: str) -&amp;gt; dict:
   return get_element_schedules(token, workspace_id, jobType='Pipeline')

def get_notebooks_schedules(token: str, workspace_id: str) -&amp;gt; dict:
   return get_element_schedules(token, workspace_id, jobType='Notebook')&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;But I'm having an error when I call theese two functions:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt;coroutine object get_job_schedules at 0x76144ee29900&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I've seen this is because of asyncronous calls. I've tried to convert as async both parent and child functions (using &lt;EM&gt;httpx&lt;/EM&gt; instead of &lt;EM&gt;request&lt;/EM&gt; because Copilot says &lt;EM&gt;async&lt;/EM&gt; is not supported by &lt;EM&gt;request&lt;/EM&gt;), but still not working. I think &lt;EM&gt;httpx&lt;/EM&gt; is not working well.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If I duplicate both functions as a copy passing the corresponding value of jobType, it works, but if I reuse the code, I get coroutine issue.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Sep 2025 13:14:44 GMT</pubDate>
    <dc:creator>amaaiia</dc:creator>
    <dc:date>2025-09-17T13:14:44Z</dc:date>
    <item>
      <title>User Data Function coroutine object error</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/User-Data-Function-coroutine-object-error/m-p/4828518#M12382</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I've created a UDF component with &lt;EM&gt;get_element_schedules(token, workspace_id, jobType)&lt;/EM&gt; function. This function returns a dict object with the list of pipelines (jobType=Pipeline) and notebooks (jobType=Notebook) in the workspace_id and the schedules associated to each pipeline/notebook. This dict object is created as a result of some calls to fabric API.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def get_element_schedules(token: str, workspace_id: str, jobType: str) -&amp;gt; dict:
   [....]
   elements_response = requests.get(elements_url, headers=headers)
   elements_data = elements_response.json().get("value", [])
   [...]
   return {"result": result}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that I want to create get_pipelines_schedules(token, workspace_id) and&amp;nbsp;get_notebooks_schedules(token, workspace_id) function as:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def get_pipelines_schedules(token: str, workspace_id: str) -&amp;gt; dict:
   return get_element_schedules(token, workspace_id, jobType='Pipeline')

def get_notebooks_schedules(token: str, workspace_id: str) -&amp;gt; dict:
   return get_element_schedules(token, workspace_id, jobType='Notebook')&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;But I'm having an error when I call theese two functions:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt;coroutine object get_job_schedules at 0x76144ee29900&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I've seen this is because of asyncronous calls. I've tried to convert as async both parent and child functions (using &lt;EM&gt;httpx&lt;/EM&gt; instead of &lt;EM&gt;request&lt;/EM&gt; because Copilot says &lt;EM&gt;async&lt;/EM&gt; is not supported by &lt;EM&gt;request&lt;/EM&gt;), but still not working. I think &lt;EM&gt;httpx&lt;/EM&gt; is not working well.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If I duplicate both functions as a copy passing the corresponding value of jobType, it works, but if I reuse the code, I get coroutine issue.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 13:14:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/User-Data-Function-coroutine-object-error/m-p/4828518#M12382</guid>
      <dc:creator>amaaiia</dc:creator>
      <dc:date>2025-09-17T13:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: User Data Function coroutine object error</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/User-Data-Function-coroutine-object-error/m-p/4828582#M12389</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="686932" data-lia-user-login="amaaiia" class="lia-mention lia-mention-user"&gt;amaaiia&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The string "&amp;lt;coroutine object ...&amp;gt;" appears when an async function is called without await. You don’t need async here unless you truly want concurrency. Use a sync HTTP client and your wrapper functions will work as-is.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Use requests or httpx in sync mode (both are fine). See HTTPX’s sync vs async note: &lt;A href="https://www.python-httpx.org/async/" target="_blank" rel="noopener"&gt;httpx async support&lt;/A&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="python"&gt;import httpx

def get_element_schedules(token: str, workspace_id: str, job_type: str) -&amp;gt; dict:
    headers = {"Authorization": f"Bearer {token}"}

    if job_type == "Pipeline":
        items_url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/datapipeline/items"
        schedule_job_type = "Pipeline"
    elif job_type == "Notebook":
        items_url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/notebook/items"
        schedule_job_type = "DefaultJob"  # notebooks use DefaultJob for schedules
    else:
        raise ValueError("job_type must be Pipeline or Notebook")

    items = httpx.get(items_url, headers=headers, timeout=60).json().get("value", [])
    result = []
    for item in items:
        item_id = item["id"]
        sched_url = (
            f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}"
            f"/items/{item_id}/jobs/{schedule_job_type}/schedules"
        )
        schedules = httpx.get(sched_url, headers=headers, timeout=60).json().get("value", [])
        result.append({"itemId": item_id, "name": item.get("displayName"), "schedules": schedules})

    return {"result": result}

def get_pipelines_schedules(token: str, workspace_id: str) -&amp;gt; dict:
    return get_element_schedules(token, workspace_id, job_type="Pipeline")

def get_notebooks_schedules(token: str, workspace_id: str) -&amp;gt; dict:
    return get_element_schedules(token, workspace_id, job_type="Notebook")&lt;/LI-CODE&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 14:31:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/User-Data-Function-coroutine-object-error/m-p/4828582#M12389</guid>
      <dc:creator>tayloramy</dc:creator>
      <dc:date>2025-09-17T14:31:34Z</dc:date>
    </item>
  </channel>
</rss>

