<?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 create_auto_cdc_from_snapshot_flow Python session resolution fails if having multiple snapshot flows in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/create-auto-cdc-from-snapshot-flow-python-session-resolution/m-p/167268#M55663</link>
    <description>&lt;P&gt;When a pipeline contains more than one create_auto_cdc_from_snapshot_flow flow (each driven by a custom Python next_snapshot_and_version function), flow resolution fails intermittently/consistently with:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;RuntimeError: The original Spark session is being accessed instead of the per-flow cloned session during parallel analysis. This is commonly caused by spawning threads inside a flow function that access the Spark session.&lt;/P&gt;&lt;P&gt;I am having functions to figure out the next snapshot like this:&lt;BR /&gt;```&lt;BR /&gt;def next_x_snapshot_and_version(latest_version):&lt;BR /&gt;versions = spark.read.table(SOURCE_TABLE).select("file_modification_time").distinct()&lt;BR /&gt;```&lt;BR /&gt;&lt;BR /&gt;Is this a bug?&lt;/P&gt;</description>
    <pubDate>Wed, 02 Sep 2026 09:43:25 GMT</pubDate>
    <dc:creator>david_aspegren</dc:creator>
    <dc:date>2026-09-02T09:43:25Z</dc:date>
    <item>
      <title>create_auto_cdc_from_snapshot_flow Python session resolution fails if having multiple snapshot flows</title>
      <link>https://community.databricks.com/t5/data-engineering/create-auto-cdc-from-snapshot-flow-python-session-resolution/m-p/167268#M55663</link>
      <description>&lt;P&gt;When a pipeline contains more than one create_auto_cdc_from_snapshot_flow flow (each driven by a custom Python next_snapshot_and_version function), flow resolution fails intermittently/consistently with:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;RuntimeError: The original Spark session is being accessed instead of the per-flow cloned session during parallel analysis. This is commonly caused by spawning threads inside a flow function that access the Spark session.&lt;/P&gt;&lt;P&gt;I am having functions to figure out the next snapshot like this:&lt;BR /&gt;```&lt;BR /&gt;def next_x_snapshot_and_version(latest_version):&lt;BR /&gt;versions = spark.read.table(SOURCE_TABLE).select("file_modification_time").distinct()&lt;BR /&gt;```&lt;BR /&gt;&lt;BR /&gt;Is this a bug?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2026 09:43:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-auto-cdc-from-snapshot-flow-python-session-resolution/m-p/167268#M55663</guid>
      <dc:creator>david_aspegren</dc:creator>
      <dc:date>2026-09-02T09:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: create_auto_cdc_from_snapshot_flow Python session resolution fails if having multiple snapshot f</title>
      <link>https://community.databricks.com/t5/data-engineering/create-auto-cdc-from-snapshot-flow-python-session-resolution/m-p/167276#M55665</link>
      <description>&lt;P&gt;This error occurs because your custom `next_x_snapshot_and_version` function references the global `spark` session variable directly, bypassing Delta Live Tables' per-flow cloned session during parallel execution. When running multiple CDC snapshot flows concurrently, DLT isolates each flow using its own cloned session; accessing global `spark` state breaks this thread safety. To fix it, update your function signature to accept a `spark_session` argument explicitly (e.g., `def next_x_snapshot_and_version(spark_session, latest_version) and pass the thread-safe `spark` instance into your custom function via a `lambda` inside your `create_auto_cdc_from_snapshot_flow` call.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2026 10:12:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-auto-cdc-from-snapshot-flow-python-session-resolution/m-p/167276#M55665</guid>
      <dc:creator>ThomasBehne</dc:creator>
      <dc:date>2026-09-02T10:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: create_auto_cdc_from_snapshot_flow Python session resolution fails if having multiple snapshot f</title>
      <link>https://community.databricks.com/t5/data-engineering/create-auto-cdc-from-snapshot-flow-python-session-resolution/m-p/167281#M55666</link>
      <description>&lt;P&gt;Thank you! I am still doing something wrong though, my function is now called like so:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;dp.&lt;/SPAN&gt;&lt;SPAN&gt;create_auto_cdc_from_snapshot_flow&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;target&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;SILVER_TABLE,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;source&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;lambda&lt;/SPAN&gt; &lt;SPAN&gt;latest_version&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;next_locations_snapshot_and_version&lt;/SPAN&gt;&lt;SPAN&gt;(spark, latest_version),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;keys&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;"location_id"&lt;/SPAN&gt;&lt;SPAN&gt;],&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;stored_as_scd_type&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;track_history_except_column_list&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;"file_modification_time"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"source_file"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"ingestion_time"&lt;/SPAN&gt;&lt;SPAN&gt;],&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;anything more i need to do to get to "pass the thread-safe `spark` instance"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 02 Sep 2026 10:50:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-auto-cdc-from-snapshot-flow-python-session-resolution/m-p/167281#M55666</guid>
      <dc:creator>david_aspegren</dc:creator>
      <dc:date>2026-09-02T10:50:48Z</dc:date>
    </item>
  </channel>
</rss>

