<?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: create_auto_cdc_from_snapshot_flow Python session resolution fails if having multiple snapshot f in Data Engineering</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>
    <dc:creator>ThomasBehne</dc:creator>
    <dc:date>2026-09-02T10:12:13Z</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>
  </channel>
</rss>

