From 921c41c987ea487e8035cad0f4db9282bfcb09b6 Mon Sep 17 00:00:00 2001 From: gibsondan Date: Thu, 8 Feb 2024 10:20:23 -0600 Subject: [PATCH] Back-compat fix for AllSelection field addition (#19677) This needs to have a null initializer to be deserialized Test Plan: Test that was failing before in master (but only on pydantic 2, which is why my testing didn't catch it, sigh) --- .../dagster/dagster/_core/definitions/asset_selection.py | 2 +- .../asset_defs_tests/test_asset_selection.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/python_modules/dagster/dagster/_core/definitions/asset_selection.py b/python_modules/dagster/dagster/_core/definitions/asset_selection.py index 398c3b1cd7b8a..7144c9106a6ce 100644 --- a/python_modules/dagster/dagster/_core/definitions/asset_selection.py +++ b/python_modules/dagster/dagster/_core/definitions/asset_selection.py @@ -426,7 +426,7 @@ def operand__str__(self) -> str: @whitelist_for_serdes class AllSelection(AssetSelection, frozen=True): - include_sources: Optional[bool] + include_sources: Optional[bool] = None def resolve_inner(self, asset_graph: AssetGraph) -> AbstractSet[AssetKey]: return ( diff --git a/python_modules/dagster/dagster_tests/asset_defs_tests/test_asset_selection.py b/python_modules/dagster/dagster_tests/asset_defs_tests/test_asset_selection.py index 4a35f71ee0112..bd815030edaa1 100644 --- a/python_modules/dagster/dagster_tests/asset_defs_tests/test_asset_selection.py +++ b/python_modules/dagster/dagster_tests/asset_defs_tests/test_asset_selection.py @@ -23,6 +23,7 @@ from dagster._core.definitions.asset_graph import AssetGraph from dagster._core.definitions.asset_selection import ( AllAssetCheckSelection, + AllSelection, AndAssetSelection, AssetCheckKeysSelection, AssetChecksForAssetKeysSelection, @@ -40,6 +41,7 @@ ) from dagster._core.definitions.assets import AssetsDefinition from dagster._core.definitions.events import AssetKey +from dagster._serdes import deserialize_value from dagster._serdes.serdes import _WHITELIST_MAP from pydantic import ValidationError from typing_extensions import TypeAlias @@ -699,3 +701,9 @@ def test_to_string_binary_operators(): def test_empty_namedtuple_truthy(): # namedtuples with no fields are still truthy assert bool(AllAssetCheckSelection.all()) + + +def test_deserialize_old_all_asset_selection(): + old_serialized_value = '{"__class__": "AllSelection"}' + new_unserialized_value = deserialize_value(old_serialized_value, AllSelection) + assert not new_unserialized_value.include_sources