Skip to content

Commit

Permalink
Convert AssetSelection subclasses from NamedTuples to Pydantic (#19197)
Browse files Browse the repository at this point in the history
## Summary & Motivation

This PR updates `AssetSelection` and its subclasses to inherit from
`pydantic.BaseModel` instead of `NamedTuple`. `NamedTuple._replace()`
was replaced by `AssetSelection.replace()`, a wrapper for `copy`
(pydantic v1) and `model_copy` (pydantic v2)

After several attempts, to make this work
- the super class `AssetSelection` must inherit from
`pydantic.BaseModel`
- the super class and subclasses must have the config `frozen=True`,
which allows all of them to be immutable, like `NamedTuple`.

Because of that, this PR udpates:
- all classes in `asset_selection.py` to reflect the changes.
- the class `DbtManifestAssetSelection` in `dagster-dbt`, which inherits
from `AssetSelection`. It is now immutable.
- the code using the classes - when inheriting from
`pydantic.BaseModel`, instantiating new objects require keyword-only
arguments except if `__init__()` is redefined for the class, so the code
was updated to use the keywords.
- the tests to reflect the changes.

## How I Tested These Changes

BK
  • Loading branch information
maximearmstrong authored Jan 25, 2024
1 parent 9f8cef5 commit ccdfdea
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 110 deletions.
Loading

0 comments on commit ccdfdea

Please sign in to comment.