Fix AssertionError crash when INFER_SCHEMA fails for JSON/ORC/AVRO files#4129
Merged
sfc-gh-helmeleegy merged 6 commits intomainfrom Mar 26, 2026
Merged
Fix AssertionError crash when INFER_SCHEMA fails for JSON/ORC/AVRO files#4129sfc-gh-helmeleegy merged 6 commits intomainfrom
sfc-gh-helmeleegy merged 6 commits intomainfrom
Conversation
When INFER_SCHEMA fails for JSON/ORC/AVRO files (e.g. malformed content triggering error 100069), the exception was silently swallowed, leaving INFER_SCHEMA=True with no schema_to_cast. This caused a downstream AssertionError with no message, hiding the actual failure from users. Now when inference fails: FileNotFoundError is re-raised directly, other errors log a warning and set INFER_SCHEMA=False so the read falls back to a single VARIANT column (matching existing CSV fallback behavior). The real Snowflake error surfaces when the data is actually queried. Made-with: Cursor
…ndling Cover three scenarios for JSON, AVRO, ORC, and Parquet formats: - Generic error: logs warning and falls back to VARIANT schema - FileNotFoundError: re-raised directly to the caller - Successful inference: no warning logged, normal behavior Made-with: Cursor
sfc-gh-aalam
approved these changes
Mar 25, 2026
sfc-gh-helmeleegy
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix AssertionError crash when INFER_SCHEMA fails for JSON/ORC/AVRO files
Summary
INFER_SCHEMAfails for semi-structured file formats (JSON, ORC, AVRO), the reader now handles the error gracefully instead of crashing with an emptyAssertionErrorFileNotFoundErrordirectly, logs a warning with the actual error for other failures, and disablesINFER_SCHEMAto fall back to$1 VARIANTschemaProblem
In
_read_semi_structured_file, when_infer_schema_for_file_format()failed (e.g., malformed JSON returning Snowflake error 100069), the exception was silently discarded andschema_to_castremainedNone. However,INFER_SCHEMAstayedTruein options, soSnowflakePlanBuilder.read_file()later hitassert schema_to_cast is not None— producing an emptyAssertionErrorwith no useful context for the user.The CSV reader (line 810-822) already handled this correctly by checking the exception, setting a fallback
schema_to_cast, and logging a warning. The JSON/ORC/AVRO path was missing this handling entirely.Before / After
AssertionErrorSnowparkSQLException(actual Snowflake error) or logged warning +$1 VARIANTfallback100069: Error parsing JSON: ...or warning with full exception details.schema()Customer Impact
Vertex Pharmaceuticals (account 3813899, va4) hit this bug in session
16380571490304122when reading malformed JSON files from an S3 stage via a Snowflake Notebook. They saw emptyAssertionErrorexceptions (SCOS error code 5001) with no indication that the underlying issue was100069: Error parsing JSON.Changes
src/snowflake/snowpark/dataframe_reader.py: In_read_semi_structured_file, when_infer_schema_for_file_format()returns an error for JSON/ORC/AVRO:FileNotFoundErrordirectly (same as CSV)INFER_SCHEMAso the downstreamassert schema_to_cast is not Nonedoesn't fireCompanion PR
This fix has a companion change in the SAS repo (
map_read_partitioned_file.py,map_read_json.py) that adds defensiveAssertionErrorhandling at the SCOS layer, converting empty assertions into descriptiveValueErrormessages with error code 5001. This ensures graceful behavior even with older Snowpark Python versions.Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-3201780
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.
Please write a short description of how your code change solves the related issue.