@@ -7686,6 +7686,75 @@ class MyTestStrategy(CustomMaterialization):
76867686 )
76877687
76887688
7689+ def test_custom_kind_lookback_property ():
7690+ """Test that CustomKind's lookback property is correctly accessed via ModelMeta.lookback.
7691+
7692+ This test verifies the fix for issue #5268 where CustomKind models were not respecting
7693+ the lookback parameter because the isinstance check for _IncrementalBy failed.
7694+ """
7695+
7696+ # Test 1: CustomKind with lookback = 3
7697+ class MyTestStrategy (CustomMaterialization ):
7698+ pass
7699+
7700+ expressions = d .parse (
7701+ """
7702+ MODEL (
7703+ name db.custom_table,
7704+ kind CUSTOM (
7705+ materialization 'MyTestStrategy',
7706+ lookback 3
7707+ )
7708+ );
7709+ SELECT a, b FROM upstream
7710+ """
7711+ )
7712+
7713+ model = load_sql_based_model (expressions )
7714+ assert model .kind .is_custom
7715+
7716+ # Verify that the kind itself has lookback = 3
7717+ kind = t .cast (CustomKind , model .kind )
7718+ assert kind .lookback == 3
7719+
7720+ # The bug: model.lookback should return 3, but with the old implementation
7721+ # using isinstance(self.kind, _IncrementalBy), it would return 0
7722+ assert model .lookback == 3 , "CustomKind lookback not accessible via model.lookback property"
7723+
7724+ # Test 2: CustomKind without lookback (should default to 0)
7725+ expressions_no_lookback = d .parse (
7726+ """
7727+ MODEL (
7728+ name db.custom_table_no_lookback,
7729+ kind CUSTOM (
7730+ materialization 'MyTestStrategy'
7731+ )
7732+ );
7733+ SELECT a, b FROM upstream
7734+ """
7735+ )
7736+
7737+ model_no_lookback = load_sql_based_model (expressions_no_lookback )
7738+ assert model_no_lookback .lookback == 0
7739+
7740+ # Test 3: Ensure IncrementalByTimeRangeKind still works correctly
7741+ incremental_expressions = d .parse (
7742+ """
7743+ MODEL (
7744+ name db.incremental_table,
7745+ kind INCREMENTAL_BY_TIME_RANGE (
7746+ time_column ds,
7747+ lookback 5
7748+ )
7749+ );
7750+ SELECT ds, a, b FROM upstream
7751+ """
7752+ )
7753+
7754+ incremental_model = load_sql_based_model (incremental_expressions )
7755+ assert incremental_model .lookback == 5
7756+
7757+
76897758def test_time_column_format_in_custom_kind ():
76907759 class TimeColumnCustomKind (CustomKind ): # type: ignore[no-untyped-def]
76917760 _time_column : TimeColumn
0 commit comments