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

[CT-2879] [Bug] UnboundLocalError: local variable 'default_agg_time_dimesion' referenced before assignment #8230

Closed
2 tasks done
QMalcolm opened this issue Jul 27, 2023 · 0 comments · Fixed by #8235
Closed
2 tasks done
Assignees
Labels
bug Something isn't working semantic Issues related to the semantic layer

Comments

@QMalcolm
Copy link
Contributor

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

In core 1.6.0rc1 if you have semantic models and metrics defined, and if a semantic model (that has no default.agg_time_dimension specified) has a measure that doesn't specify a agg_time_dimension then when you run dbt parse you get the error

An error occurred while checking aggregation time dimension for a semantic model - UnboundLocalError: local variable 'default_agg_time_dimesion' referenced before assignment

Expected Behavior

If a semantic model (that has no default.agg_time_dimension specified) has a measure that doesn't specify a agg_time_dimension then when you run dbt parse then a validation issue should be logged

Aggregation time dimension for measure {measure.name} is not set! This should either be set directly on the measure specification in the model, or else defaulted to the primary time dimension in the data source containing the measure.

Steps To Reproduce

  1. Define a measure without a agg_time_dimension on a semantic model which doesn't have a default agg_time_dimension set
  2. Run dbt parse
  3. be sad about an UnboundLocalError

Relevant log output

An error occurred while checking aggregation time dimension for a semantic model - UnboundLocalError: local variable 'default_agg_time_dimesion' referenced before assignment

This happens due to a logical error in

if self.defaults is not None:
. Specifically if a semantic model doesn't have defaults defined, and a measure of that semantic model doesn't have an agg_time_dimension we try to set it to the detected default value (which due to the logical error hasn't been bound). It's kind of ironic because we're blowing up on the thing we're trying to detect.



### Environment

```markdown
- OS: macOS 13.4.1 (Ventura)
- Python: 3.8.10
- dbt: 1.6.0rc1

Which database adapter are you using with dbt?

No response

Additional Context

The fix is to change this if statement to

default_agg_time_dimension = self.defaults.agg_time_dimension if self.defaults is not None else None
@QMalcolm QMalcolm added bug Something isn't working semantic Issues related to the semantic layer labels Jul 27, 2023
@QMalcolm QMalcolm self-assigned this Jul 27, 2023
@github-actions github-actions bot changed the title [Bug] UnboundLocalError: local variable 'default_agg_time_dimesion' referenced before assignment [CT-2879] [Bug] UnboundLocalError: local variable 'default_agg_time_dimesion' referenced before assignment Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working semantic Issues related to the semantic layer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant