Skip to content

Commit

Permalink
more testing around default field deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Apr 30, 2024
1 parent a941b93 commit 3b0041f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions core/dbt/artifacts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ All existing resources are defined under `dbt/artifacts/resources/v1`.
Freely make incremental, non-breaking changes in-place to the latest major version of any artifact in mantle (via minor or patch bumps). The only changes that are fully forward and backward compatible are:
1. Adding a new field with a default
2. Deleting a field with a default
* This is compatible in terms of serialization and deserialization in mashumaro, but still may be surprising for consumers relying on the fields existence (e.g. `manifest["deleted_field]` will stop working unless the access was implemented safely )
* This is compatible in terms of serialization and deserialization, but still may be lead to suprising behaviour:
* For artifact consumers relying on the fields existence (e.g. `manifest["deleted_field"]` will stop working unless the access was implemented safely)
* Old code (e.g. in dbt-core) that relies on the value of the deleted field may have surprising behaviour given only the default value will be set when instantiated from the new schema

These types of minor, non-reabking changes are tested by [tests/unit/artifacts/test_base_resource.py::TestMinorSchemaChange](https://github.com/dbt-labs/dbt-core/blob/main/tests/unit/artifacts/test_base_resource.py).
These types of minor, non-breaking changes are tested by [tests/unit/artifacts/test_base_resource.py::TestMinorSchemaChange](https://github.com/dbt-labs/dbt-core/blob/main/tests/unit/artifacts/test_base_resource.py).

### Breaking changes
A breaking change is anything that:
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/artifacts/test_base_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@dataclass
class BaseResourceWithDefaultField(BaseResource):
new_field_with_default: bool = True
field_with_default: bool = True


class TestMinorSchemaChange:
Expand All @@ -31,7 +31,7 @@ def base_resource_new_default_field(self):
path="test_path",
original_file_path="test_original_file_path",
unique_id="test_unique_id",
new_field_with_default=False,
field_with_default=False,
)

def test_serializing_new_default_field_is_backward_compatabile(
Expand All @@ -46,7 +46,9 @@ def test_serializing_new_default_field_is_forward_compatible(self, base_resource

def test_serializing_removed_default_field_is_backward_compatabile(self, base_resource):
# old code (using old class with default field) can create an instance of itself given new data (class w/o default field)
BaseResourceWithDefaultField.from_dict(base_resource.to_dict())
old_resource = BaseResourceWithDefaultField.from_dict(base_resource.to_dict())
# set to the default value when not provided in data
assert old_resource.field_with_default is True

def test_serializing_removed_default_field_is_forward_compatible(
self, base_resource_new_default_field
Expand Down

0 comments on commit 3b0041f

Please sign in to comment.