@@ -299,9 +299,9 @@ def get_report_chart_data(
299299 def create_snapshot (
300300 title : str ,
301301 dashboard_id : int ,
302- date_column : Dict [str , str ],
303- period_end : date ,
304302 orguser : OrgUser ,
303+ date_column : Optional [Dict [str , str ]] = None ,
304+ period_end : Optional [date ] = None ,
305305 period_start : Optional [date ] = None ,
306306 ) -> ReportSnapshot :
307307 """Create a snapshot from a dashboard.
@@ -314,10 +314,11 @@ def create_snapshot(
314314 Args:
315315 title: User-provided title for the snapshot
316316 dashboard_id: ID of the dashboard to snapshot
317- date_column: Dictionary with {schema_name, table_name, column_name}
318- identifying the datetime column for period filtering
319- period_end: End of reporting period (inclusive)
320317 orguser: The user creating the snapshot
318+ date_column: Dictionary with {schema_name, table_name, column_name}
319+ identifying the datetime column for period filtering.
320+ None for dashboards without datetime columns.
321+ period_end: End of reporting period (inclusive). None when no date filtering.
321322 period_start: Start of reporting period (inclusive). None means no lower bound.
322323
323324 Returns:
@@ -328,7 +329,7 @@ def create_snapshot(
328329 dashboard doesn't exist, or date_column is
329330 not a valid datetime column in the warehouse
330331 """
331- if period_start is not None and period_start > period_end :
332+ if period_start is not None and period_end is not None and period_start > period_end :
332333 raise SnapshotValidationError ("period_start must be before period_end" )
333334
334335 # Fetch dashboard with filters prefetched (used only for freezing)
@@ -339,45 +340,45 @@ def create_snapshot(
339340 except Dashboard .DoesNotExist :
340341 raise SnapshotValidationError (f"Dashboard { dashboard_id } not found" )
341342
342- # Validate date_column: first check dashboard filters, then fall back
343- # to verifying the column exists in the warehouse as a datetime type
344- datetime_filters = dashboard .filters .filter (filter_type = "datetime" )
345- match_on_filter = datetime_filters .filter (
346- schema_name = date_column ["schema_name" ],
347- table_name = date_column ["table_name" ],
348- column_name = date_column ["column_name" ],
349- ).exists ()
350-
351- if not match_on_filter :
352- # Fallback: verify the column exists in the warehouse as datetime
353- org_warehouse = OrgWarehouse .objects .filter (org = orguser .org ).first ()
354- if not org_warehouse :
355- raise SnapshotValidationError ("Warehouse not configured" )
356-
357- warehouse_client = WarehouseFactory .get_warehouse_client (org_warehouse )
358- all_columns = warehouse_client .get_table_columns (
359- date_column ["schema_name" ],
360- date_column ["table_name" ],
361- )
362-
363- # Find the specific column
364- target_col = None
365- for col in all_columns :
366- if col ["name" ] == date_column ["column_name" ]:
367- target_col = col
368- break
369-
370- if not target_col :
371- raise SnapshotValidationError (
372- f"Column '{ date_column ['column_name' ]} ' not found in "
373- f"{ date_column ['schema_name' ]} .{ date_column ['table_name' ]} "
343+ # Validate date_column if provided
344+ if date_column :
345+ datetime_filters = dashboard .filters .filter (filter_type = "datetime" )
346+ match_on_filter = datetime_filters .filter (
347+ schema_name = date_column ["schema_name" ],
348+ table_name = date_column ["table_name" ],
349+ column_name = date_column ["column_name" ],
350+ ).exists ()
351+
352+ if not match_on_filter :
353+ # Fallback: verify the column exists in the warehouse as datetime
354+ org_warehouse = OrgWarehouse .objects .filter (org = orguser .org ).first ()
355+ if not org_warehouse :
356+ raise SnapshotValidationError ("Warehouse not configured" )
357+
358+ warehouse_client = WarehouseFactory .get_warehouse_client (org_warehouse )
359+ all_columns = warehouse_client .get_table_columns (
360+ date_column ["schema_name" ],
361+ date_column ["table_name" ],
374362 )
375363
376- if target_col .get ("translated_type" ) != TranslateColDataType .DATETIME :
377- raise SnapshotValidationError (
378- f"Column '{ date_column ['column_name' ]} ' is not a datetime column "
379- f"(type: { target_col ['data_type' ]} )"
380- )
364+ # Find the specific column
365+ target_col = None
366+ for col in all_columns :
367+ if col ["name" ] == date_column ["column_name" ]:
368+ target_col = col
369+ break
370+
371+ if not target_col :
372+ raise SnapshotValidationError (
373+ f"Column '{ date_column ['column_name' ]} ' not found in "
374+ f"{ date_column ['schema_name' ]} .{ date_column ['table_name' ]} "
375+ )
376+
377+ if target_col .get ("translated_type" ) != TranslateColDataType .DATETIME :
378+ raise SnapshotValidationError (
379+ f"Column '{ date_column ['column_name' ]} ' is not a datetime column "
380+ f"(type: { target_col ['data_type' ]} )"
381+ )
381382
382383 frozen_dashboard = FrozenDashboardConfig (
383384 ** ReportService ._freeze_dashboard (dashboard )
0 commit comments