dbt-labs/dbt_metrics

[SEMANTIC-90] [Bug] Metric definition issue with custom schema macro

Closed this issue · 6 comments

Is this a new bug in dbt_metrics?

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

Current Behavior

When attempting to run a metric (in Mode), I get the following error message:

net.snowflake.client.jdbc.SnowflakeSQLException: SQL compilation error:
Schema 'DATABASE.TARGET_SCHEMA_CUSTOM_SCHEMA' does not exist or not authorized.

Which makes sense because the models are actually materialized in CUSTOM_SCHEMA

Expected Behavior

The metric reference should take into account the fact that the model schema rules have been customized using a custom get_custom_schema.sql macro.

Steps To Reproduce

Use the following custom schema macro:

{% macro generate_schema_name(custom_schema_name, node) -%}
    {%- set default_schema = target.schema -%}
    {%- if target.name == 'prod'  -%}
        {%- if custom_schema_name is not none -%}
            {{ custom_schema_name }}
        {%- else -%}
            {{ default_schema }}
        {%- endif -%}
    {%- else -%}
        {%- if custom_schema_name is not none -%}
            {{ default_schema }}_{{ custom_schema_name }} 
        {%- else -%}
            {{ default_schema }}
        {%- endif -%}
    {%- endif -%}
{%- endmacro %}

Then define a metric and attempt to visualize it in Mode Analytics.

Relevant log output

No response

Environment

- dbt-adapter & version: dbt-snowflake v1.3.0
- dbt_metrics version: 1.3.0

Which database adapter are you using with dbt?

snowflake

Additional Context

Community slack: https://getdbt.slack.com/archives/C046L0VTVR6/p1668870928882369?thread_ts=1668868370.759179&cid=C046L0VTVR6

Hi @raphaelvarieras ! Would you be able to go to your environment settings in dbt Cloud? If you hit edit and pull up the semantic layer information, you should see a target name similar to the screenshot:

image

If you change that to prod (based on your macro above), I believe that should resolve the issue.

Hey @callum-mcdata - thanks for the advice! I checked my environment settings in dbt Cloud and it's already set up as prod unfortunately so that may not be the culprit in my case.

@raphaelvarieras can you provide a screenshot of the target name in the semantic layer section? I wasn't able to recreate this error once I'd resolved the target issue so I just want to visually confirm that it isn't this

Sure thing - is this what you wanted to see?

Screenshot 2022-11-21 at 12 41 12 PM

Hey @raphaelvarieras it appears that this is a bug with the Semantic Layer - unfortunately we're in a code freeze for this week due to the holidays but our engineers will begin scoping it out this week. As soon as I have more tactical information I'll be sure to let you know!

Hi folks! For anyone following along with this, we've released a fix to this in the Semantic Layer. Your target name now correctly flows through into the semantic layer but it is set at the time of creation. The ability to edit them will be addressed in a future release but we wanted to make sure everyone is unblocked.

If you have personally run into this issue, please email me your accountID, environmentID and desired target name at callum.mccann@dbtlabs.com or message me on the Community Slack. We will be able to get your semantic layer updated and ready to go!