Fix and tests for SPARK-3853