Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code to work with mashumaro 3.15 #11051

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Fix code to work with mashumaro 3.15 #11051

wants to merge 45 commits into from

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Nov 25, 2024

Resolves #11044

Problem

Mashumaro 3.15 caused some breakages in our code.

Solution

In a couple of cases, Unions had to be adjusted to de-serialize and serialize in the right order. Most of the effort went into refactoring the update node config code so that "from_dict" was not performed until after validation, so that config values were not converted to valid forms prior to being validated. In general the pattern is that all sources of configs should be combined as dictionaries, then validated, then used to construct a valid config object.

dbt-common BaseConfig.update_from method had to be converted to a class method and the "from_dict" removed.

Since there were already a bunch of changes in core/dbt/context/context_config.py, I also took the opportunity to rename ContextConfig to ConfigBuilder, and replace variables and parameters using it in the rest of the parsing codebase.

Since the hooks needed to be fixed prior to validation in generate_node_config, I moved the hook fixing method to context_config.py and removed it from parser/base.py.

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@gshank gshank requested a review from a team as a code owner November 25, 2024 23:02
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

Attention: Patch coverage is 96.89119% with 6 lines in your changes missing coverage. Please review.

Project coverage is 88.87%. Comparing base (97ffc37) to head (5f94de5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11051   +/-   ##
=======================================
  Coverage   88.86%   88.87%           
=======================================
  Files         187      187           
  Lines       24028    24004   -24     
=======================================
- Hits        21353    21333   -20     
+ Misses       2675     2671    -4     
Flag Coverage Δ
integration 86.18% <93.78%> (+<0.01%) ⬆️
unit 62.01% <84.45%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 62.01% <84.45%> (-0.01%) ⬇️
Integration Tests 86.18% <93.78%> (+<0.01%) ⬆️

@gshank gshank requested a review from a team as a code owner November 26, 2024 02:58
@gshank gshank requested review from jcserv and removed request for a team November 26, 2024 02:58
@cla-bot cla-bot bot added the cla:yes label Nov 26, 2024
@gshank gshank changed the title Fix NodeVersion definition, make_semantic_model utility Fix code to work with mashumaro 3.15 Dec 2, 2024
@gshank
Copy link
Contributor Author

gshank commented Dec 5, 2024

Also see dbt-labs/dbt-common#228

@gshank
Copy link
Contributor Author

gshank commented Dec 10, 2024

Fatal1ty/mashumaro#269

own_config = self.get_node_project(project_name)
) -> Dict[str, Any]:
"""This method takes resource configs from the project, the model (if applicable),
and the patch, and combines them into one config dictionary."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole method is so much more readable now, thank you ✨

finalized = config.finalize_and_validate()
return finalized.to_dict(omit_none=True)
config_cls.validate(config_dict)
config_obj = config_cls.from_dict(config_dict)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm noticing we are no longer omitting None values during construction here.

Is the implication of that that even None configurations will make their way onto the parsed node representation + get serialized out? I don't think this is a huge deal, just trying to wrap my head around any potential downsides of the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config_dict is the merged dicts from all the various sources, and the method actually returns a config obj. It doesn't really matter whether you've omitted the None fields when constructing an object. This is called in build_config_dict, which converts it to a dictionary with omit_none, so it should actually be the same dictionary that was being returned before.

for hook in hooks:
get_rendered(hook.sql, context, parsed_node, capture_macros=True)

def initial_config(self, fqn: List[str]) -> ContextConfig:
config_version = min([self.project.config_version, self.root_project.config_version])
if config_version == 2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to remove this check entirely at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config_version == 2? Yeah, we haven't required that or checked in at least a year and a half. I think pre-version-2 was way back in... version 14? Before I started anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mashumaro incompatibility: node.external.partitions returned as string instead of dict
2 participants