Skip to content

fix: preserve exception args when serializing built-in exceptions#69766

Open
Vishwaspatel2401 wants to merge 1 commit into
apache:mainfrom
Vishwaspatel2401:fix-exception-args-serialization
Open

fix: preserve exception args when serializing built-in exceptions#69766
Vishwaspatel2401 wants to merge 1 commit into
apache:mainfrom
Vishwaspatel2401:fix-exception-args-serialization

Conversation

@Vishwaspatel2401

Copy link
Copy Markdown
Contributor

Description

BaseSerialization was adding an extra list/tuple layer around the args of built-in exceptions such as KeyError and AttributeError during serialization.

"args": [var.args]

Because var.args is already a tuple, an exception such as KeyError("boom") was serialized incorrectly:

from airflow.serialization.serialized_objects import BaseSerialization

result = BaseSerialization.deserialize(
    BaseSerialization.serialize(KeyError("boom"))
)

result.args  # (("boom",),) instead of ("boom",)

This change preserves the exception’s original args exactly during serialization and deserialization.

Closes #69743.

Tests

Added parametrized test cases to test_serialize_deserialize in test_serialized_objects.py covering:

  • KeyError("boom")
  • AttributeError("boom")
  • KeyError("a", "b")

The tests verify that .args is preserved exactly after serialization and deserialization. All 40 parametrized test cases pass.


Was generative AI tooling used to co-author this PR?
  • Yes

Generated-by: Claude Code, used in accordance with the project’s contribution guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BaseSerialization adds an extra tuple layer to built-in exception args

1 participant