@@ -745,6 +745,9 @@ def _augment_response_with_on_demand_transforms(
745745 ) or not getattr (odfv , "write_to_online_store" , True )
746746
747747 if should_transform :
748+ # Initialize transformed_features to avoid UnboundLocalError
749+ transformed_features = None
750+
748751 # Apply aggregations if configured.
749752 aggregations = getattr (odfv , "aggregations" , [])
750753 mode_attr = getattr (odfv , "mode" , "pandas" )
@@ -771,6 +774,16 @@ def _augment_response_with_on_demand_transforms(
771774 mode ,
772775 )
773776
777+ # If only aggregations were applied and no transformations will follow,
778+ # set transformed_features to avoid UnboundLocalError.
779+ # This handles the case where aggregations exist but the ODFV has no transformations.
780+ if not hasattr (odfv , "feature_transformation" ) or not odfv .feature_transformation :
781+ # No transformations will be applied, set transformed_features to aggregated result
782+ if mode == "python" and initial_response_dict is not None :
783+ transformed_features = initial_response_dict
784+ elif mode in {"pandas" , "substrait" } and initial_response_arrow is not None :
785+ transformed_features = initial_response_arrow
786+
774787 # Apply transformation. Note: aggregations and transformation configs are mutually exclusive
775788 # TODO: Fix to make it work for having both aggregation and transformation
776789 # ticket: https://github.com/feast-dev/feast/issues/5689
@@ -822,6 +835,12 @@ def _augment_response_with_on_demand_transforms(
822835 raise Exception (
823836 f"Invalid OnDemandFeatureMode: { mode } . Expected one of 'pandas', 'python', or 'substrait'."
824837 )
838+
839+ # Handle case where no transformation was applied
840+ if transformed_features is None :
841+ # No transformation was applied, skip this ODFV
842+ continue
843+
825844 transformed_columns = (
826845 transformed_features .column_names
827846 if isinstance (transformed_features , pyarrow .Table )
0 commit comments