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 case sensitivity for grain_to_date and offset_to_grain #370

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

Conversation

courtneyholcomb
Copy link
Contributor

Description

In this PR, we unintentionally made grain_to_date and offset_to_grain fields case sensitive. This needs to be fixed before we can release to core.

Checklist

if metric.type_params.grain_to_date and not metric.type_params.cumulative_type_params.grain_to_date:
metric.type_params.cumulative_type_params.grain_to_date = metric.type_params.grain_to_date.value

# Since grain_to_date is just a string, we can't add custom parsing to them. Instead, lowercase them here.
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually... you can, I think? I might be missing some critical context here on how these values are processed, but you can override the parse_obj function in the Pydantic class that includes this string to change the behavior. (This took me an embarrassingly long time to figure out.)

I did this in #366 in dbt_semantic_interfaces/implementations/saved_query.py to differentiate between str and List[str].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Silly me!

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh no please don't say that. Like I said, this took me way longer to figure out than I'd like to talk about, so if you're silly, then what am I?!?

Copy link
Contributor

Choose a reason for hiding this comment

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

image

for semantic_model in model.semantic_models:
semantic_model.name = semantic_model.name.lower()
for metric in model.metrics:
metric.name = metric.name.lower()
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't one of the fixes mentioned in the description, is it?

window: "7 Days"
"""
)
for yaml_contents in (yaml_contents1, yaml_contents2):
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting a for loop in to a test case to run multiple tests inside is generally an antipattern in test design. Test functions should be as simple as possible.

In this case, you could create two separate functions with a helper, or you could get fancy and use a data provider. (I think this is pytest, in which case, you might be able to use https://docs.pytest.org/en/stable/how-to/parametrize.html , but i say that without considering what version we use or anything else.)

@@ -240,17 +263,35 @@ def test_grain_to_date_metric_parsing() -> None:
grain_to_date: "weEk"
"""
)
file = YamlConfigFile(filepath="inline_for_test", contents=yaml_contents)
yaml_contents2 = textwrap.dedent(
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto.

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.

2 participants