<?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 Re: Databricks Connect + AutoDependencies + UDF + Streaming breaks in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173663#M56742</link>
    <description>&lt;P&gt;Quick follow-up: I reproduced the hook failure locally with the latest databricks-connect (19.2.0). foreachBatch sends its function as a PythonUDF message, but its command is just the pickled function, not the (func, return_type) tuple the hook expects. So the UDF inside your batch isn't the trigger: any foreachBatch combined with withAutoDependencies() hits this error, and it's still present in the latest version.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Oct 2026 17:39:07 GMT</pubDate>
    <dc:creator>Jen_Evangelista</dc:creator>
    <dc:date>2026-10-16T17:39:07Z</dc:date>
    <item>
      <title>Databricks Connect + AutoDependencies + UDF + Streaming breaks</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173335#M56719</link>
      <description>&lt;P&gt;I have this toy python script:&lt;/P&gt;&lt;PRE&gt;CATALOG = 'mpt_usd_gbl_bronze_dev' # &amp;lt;-- replace&lt;BR /&gt;SCHEMA = 'mpt_gbl_tco_fof' # &amp;lt;-- replace&lt;BR /&gt;&lt;BR /&gt;src=f'{CATALOG}.{SCHEMA}.toy_source'&lt;BR /&gt;DEST = f'{CATALOG}.{SCHEMA}.toy_dest'&lt;BR /&gt;&lt;BR /&gt;from databricks.connect import DatabricksSession, DatabricksEnv&lt;BR /&gt;from pyspark.sql import functions as F, SparkSession, DataFrame&lt;BR /&gt;&lt;BR /&gt;env = DatabricksEnv().withAutoDependencies(upload_local=True, use_index=True)&lt;BR /&gt;spark: SparkSession = DatabricksSession.builder.serverless().withEnvironment(env).getOrCreate()&lt;BR /&gt;&lt;BR /&gt;spark.sql(f'CREATE SCHEMA IF NOT EXISTS {CATALOG}.{SCHEMA}')&lt;BR /&gt;spark.sql(f'DROP TABLE IF EXISTS {SRC}')&lt;BR /&gt;spark.sql(f'DROP TABLE IF EXISTS {DEST}')&lt;BR /&gt;&lt;BR /&gt;(&lt;BR /&gt;    spark.createDataFrame(&lt;BR /&gt;        [('Alice', 1), ('Bob', 2), ('Claire', 3),],&lt;BR /&gt;        schema='name string, value int',&lt;BR /&gt;    )&lt;BR /&gt;    .write.format('delta')&lt;BR /&gt;    .saveAsTable(SRC)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;def test(batch_df: DataFrame, batch_id: int):&lt;BR /&gt;f = F.udf(lambda x: 'here')&lt;BR /&gt;(&lt;BR /&gt;    batch_df&lt;BR /&gt;    .withColumn('here', f(F.col('file_name')))&lt;BR /&gt;    .write.format('delta').mode('append')&lt;BR /&gt;    .saveAsTable(DEST)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;(&lt;BR /&gt;    spark&lt;BR /&gt;    .readStream.format('delta').table(SRC)&lt;BR /&gt;    .writeStream.foreachBatch(test)&lt;BR /&gt;    .trigger(availableNow=True).start().awaitTermination()&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;It (1) initializes databricks-connect (2) loads dependencies (3) creates a UDF (4) runs a streaming query. I am getting this error:&lt;/P&gt;&lt;PRE&gt;Traceback (most recent call last):&lt;BR /&gt;File "/home/ivaylo-rusinov/tieto/magna/MPT_Cloud_Data_Analytics/MPT_UNS_Engineering_Pipeline_3S/PipelineConfigurations/MPT_GBL_Workspace/SourceAligned_GBL_TCO_FoF/tests3.py", line 40, in &amp;lt;module&amp;gt;&lt;BR /&gt;.trigger(availableNow=True).start().awaitTermination()&lt;BR /&gt;^^^^^^^&lt;BR /&gt;File "/home/ivaylo-rusinov/python_312_env/lib/python3.12/site-packages/pyspark/sql/connect/streaming/readwriter.py", line 793, in start&lt;BR /&gt;return self._start_internal(&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/home/ivaylo-rusinov/python_312_env/lib/python3.12/site-packages/pyspark/sql/connect/streaming/readwriter.py", line 755, in _start_internal&lt;BR /&gt;_, properties, _ = self._session.client.execute_command(cmd)&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/home/ivaylo-rusinov/python_312_env/lib/python3.12/site-packages/pyspark/sql/connect/client/core.py", line 1880, in execute_command&lt;BR /&gt;data, _, metrics, observed_metrics, properties = self._execute_and_fetch(&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/home/ivaylo-rusinov/python_312_env/lib/python3.12/site-packages/pyspark/sql/connect/client/core.py", line 2512, in _execute_and_fetch&lt;BR /&gt;for response in self._execute_and_fetch_as_iterator(&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/home/ivaylo-rusinov/python_312_env/lib/python3.12/site-packages/pyspark/sql/connect/client/core.py", line 2266, in _execute_and_fetch_as_iterator&lt;BR /&gt;req = hook.on_execute_plan(req)&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/home/ivaylo-rusinov/python_312_env/lib/python3.12/site-packages/databricks/connect/auto_dependencies/hook.py", line 110, in on_execute_plan&lt;BR /&gt;obj = obj[0]&lt;BR /&gt;~~~^^^&lt;BR /&gt;TypeError: 'function' object is not subscriptable&lt;/PRE&gt;&lt;P&gt;Is this intended behavior? I assume this is quite a common workflow. How can I fix this?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2026 17:46:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173335#M56719</guid>
      <dc:creator>i4ata</dc:creator>
      <dc:date>2026-10-14T17:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks Connect + AutoDependencies + UDF + Streaming breaks</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173660#M56741</link>
      <description>&lt;P&gt;Looking at the traceback, the failure happens inside the auto-dependencies hook (auto_dependencies/hook.py, on_execute_plan), not in your code. When the plan contains a foreachBatch function, the hook receives the bare function object and tries to index it (obj[0]), which raises "'function' object is not subscriptable". So it looks like a bug in how withAutoDependencies handles foreachBatch, not intended behavior.&lt;/P&gt;&lt;P&gt;Workarounds while it gets fixed:&lt;/P&gt;&lt;P&gt;1. Drop withAutoDependencies() for this job and declare dependencies explicitly with DatabricksEnv().withDependencies([...]). You lose the automatic detection, but the streaming query starts normally.&lt;/P&gt;&lt;P&gt;2. Keep auto-dependencies for interactive/batch work and run the streaming part as a job (wheel or notebook task), which is closer to how it will run in production anyway.&lt;/P&gt;&lt;P&gt;Two small things in the snippet, unrelated to the error: src is defined in lowercase but SRC is used later, and the UDF reads a file_name column that doesn't exist in toy_source, so the batch will fail once the hook issue is out of the way.&lt;/P&gt;&lt;P&gt;I'd also report it with your databricks-connect version (pip show databricks-connect), since this is a clear, reproducible case.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2026 17:25:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173660#M56741</guid>
      <dc:creator>Jen_Evangelista</dc:creator>
      <dc:date>2026-10-16T17:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks Connect + AutoDependencies + UDF + Streaming breaks</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173663#M56742</link>
      <description>&lt;P&gt;Quick follow-up: I reproduced the hook failure locally with the latest databricks-connect (19.2.0). foreachBatch sends its function as a PythonUDF message, but its command is just the pickled function, not the (func, return_type) tuple the hook expects. So the UDF inside your batch isn't the trigger: any foreachBatch combined with withAutoDependencies() hits this error, and it's still present in the latest version.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2026 17:39:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173663#M56742</guid>
      <dc:creator>Jen_Evangelista</dc:creator>
      <dc:date>2026-10-16T17:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks Connect + AutoDependencies + UDF + Streaming breaks</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173708#M56754</link>
      <description>&lt;P&gt;Thanks for the reply and apologies for the typos in the snippet! I tried to get withDependencies() to work but as my UDF was requiring an external package, it was still failing. It can be replicated with the following snippet:&lt;/P&gt;&lt;PRE&gt;CATALOG = 'catalog' # &amp;lt;-- replace&lt;BR /&gt;SCHEMA = 'schema' # &amp;lt;-- replace&lt;BR /&gt;&lt;BR /&gt;src=f'{CATALOG}.{SCHEMA}.toy_source'&lt;BR /&gt;DEST = f'{CATALOG}.{SCHEMA}.toy_dest'&lt;BR /&gt;&lt;BR /&gt;from databricks.connect import DatabricksSession, DatabricksEnv&lt;BR /&gt;from pyspark.sql import functions as F, SparkSession, DataFrame&lt;BR /&gt;import openpyxl&lt;BR /&gt;&lt;BR /&gt;env = DatabricksEnv().withDependencies('openpyxl')&lt;BR /&gt;spark: SparkSession = DatabricksSession.builder.serverless().withEnvironment(env).getOrCreate()&lt;BR /&gt;&lt;BR /&gt;spark.sql(f'CREATE SCHEMA IF NOT EXISTS {CATALOG}.{SCHEMA}')&lt;BR /&gt;spark.sql(f'DROP TABLE IF EXISTS {SRC}')&lt;BR /&gt;spark.sql(f'DROP TABLE IF EXISTS {DEST}')&lt;BR /&gt;&lt;BR /&gt;spark.createDataFrame([('Alice', 1), ('Bob', 2)], schema='name string, value int').write.format('delta').saveAsTable(SRC)&lt;BR /&gt;f = F.udf(lambda x: x + openpyxl.__version__)&lt;BR /&gt;def test(batch_df: DataFrame, batch_id: int):&lt;BR /&gt;  batch_df.withColumn('here', f(F.col('name'))).write.format('delta').mode('overwrite').saveAsTable(DEST)&lt;BR /&gt;&lt;BR /&gt;spark.readStream.format('delta').table(SRC).writeStream.foreachBatch(test).trigger(availableNow=True).start().awaitTermination()&lt;/PRE&gt;&lt;P&gt;This results in:&lt;/P&gt;&lt;PRE&gt;File "/databricks/spark/python/_engine_pyspark.zip/_engine_pyspark/sql/connect/streaming/worker/foreach_batch_worker.py", line 173, in main&lt;BR /&gt;process(df_ref_id, int(batch_id))&lt;BR /&gt;File "/databricks/spark/python/_engine_pyspark.zip/_engine_pyspark/sql/connect/streaming/worker/foreach_batch_worker.py", line 77, in process&lt;BR /&gt;func(batch_df, batch_id)&lt;BR /&gt;File "/home/ivaylo-rusinov/databricks_forums/main.py", line 21, in test&lt;BR /&gt;File "/databricks/python3/lib/python3.12/site-packages/pyspark/sql/connect/readwriter.py", line 828, in saveAsTable&lt;BR /&gt;_, _, ei = self._spark.client.execute_command(&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/databricks/python3/lib/python3.12/site-packages/pyspark/sql/connect/client/core.py", line 1812, in execute_command&lt;BR /&gt;data, _, metrics, observed_metrics, properties = self._execute_and_fetch(&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/databricks/python3/lib/python3.12/site-packages/pyspark/sql/connect/client/core.py", line 2411, in _execute_and_fetch&lt;BR /&gt;for response in self._execute_and_fetch_as_iterator(&lt;BR /&gt;File "/databricks/python3/lib/python3.12/site-packages/pyspark/sql/connect/client/core.py", line 2387, in _execute_and_fetch_as_iterator&lt;BR /&gt;self._handle_error(error, req.operation_id)&lt;BR /&gt;File "/databricks/python3/lib/python3.12/site-packages/pyspark/sql/connect/client/core.py", line 2785, in _handle_error&lt;BR /&gt;self._handle_rpc_error(error)&lt;BR /&gt;File "/databricks/python3/lib/python3.12/site-packages/pyspark/sql/connect/client/core.py", line 2882, in _handle_rpc_error&lt;BR /&gt;raise convert_exception(&lt;BR /&gt;File "/databricks/python3/lib/python3.12/site-packages/pyspark/cloudpickle/cloudpickle.py", line 475, in subimport&lt;BR /&gt;__import__(name)&lt;BR /&gt;^^^^^^^^^^^^^^^&lt;BR /&gt;pyspark.errors.exceptions.connect.PythonException: &lt;BR /&gt;An exception was thrown from the Python worker. Please see the stack trace below.&lt;BR /&gt;[PYTHON_EXCEPTION] An exception was thrown from the Python worker: Traceback (most recent call last):&lt;BR /&gt;File "/databricks/python3/lib/python3.12/site-packages/pyspark/cloudpickle/cloudpickle.py", line 475, in subimport&lt;BR /&gt;__import__(name)&lt;BR /&gt;ModuleNotFoundError: No module named 'openpyxl'&lt;/PRE&gt;&lt;P&gt;I am also using databricks-connect 19.2.0. This runs fine outside of `foreachBatch`. I guess the functionality is just too limited.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Oct 2026 11:58:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-connect-autodependencies-udf-streaming-breaks/m-p/173708#M56754</guid>
      <dc:creator>i4ata</dc:creator>
      <dc:date>2026-10-17T11:58:20Z</dc:date>
    </item>
  </channel>
</rss>

