question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue when parsing dbt models

See original GitHub issue

Hey folks!

I’ve just run ‘dbt2looker’ in my local dbt repo folder, and I receive the following error:

❯ dbt2looker
12:11:54 ERROR  Cannot parse model with id: "model.smallpdf.brz_exchange_rates" - is the model file empty?
Failed

The model file itself (pictured below) is not empty, therefore I am not sure what the issue with parsing this model dbt2looker appears to have. It is not materialised as a table or view, it is utilised by dbt as ephemeral - is that of importance when parsing files in the project? I’ve also tried running dbt2looker on a limited subset of dbt models via a tag, the same error appears. Any help is greatly appreciated!

Screenshot 2022-06-20 at 12 12 22

Other details:

  • on dbt version dbt 1.0.0
  • using dbt-redshift adapter dbt-redshift@1.0.0
  • let me know if anything else is of importance!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
boludo00commented, Jul 8, 2022

So yesterday I was modding the code and was able to get past the - is the model file empty? error.

Since the parser uses the manifest.json file, a node has its materialization in the config object:

"config": {
    "enabled": true,
    "alias": null,
    "schema": "staging",
    "database": null,
    "tags": [],
    "meta": {},
    "materialized": "ephemeral",
    "persist_docs": {},
    "quoting": {},
    "column_types": {},
    "full_refresh": null,
    "on_schema_change": "ignore",
    "bind": false,
    "post-hook": [],
    "pre-hook": []
},

If the DbtNode changes to:

class DbtNode(BaseModel):
    unique_id: str
    resource_type: str
    config: Dict[str, Any]

then the parse_models() method could be modified to:

def parse_models(raw_manifest: dict, tag=None) -> List[models.DbtModel]:
    manifest = models.DbtManifest(**raw_manifest)
    all_models: List[models.DbtModel] = [
        node
        for node in manifest.nodes.values()
        if node.resource_type == 'model' and node.config['materialized'] != 'ephemeral'
    ]

    # Empty model files have many missing parameters
    for model in all_models:
        if not hasattr(model, 'name'):
            logging.error('Cannot parse model with id: "%s" - is the model file empty?', model.unique_id)
            raise SystemExit('Failed')

    if tag is None:
        return all_models
    return [model for model in all_models if tags_match(tag, model)]

which should ensure the list of models only contains DbtModel instances. This might be overkill as a solution and maybe even not the intended effect but it solve those issues for me. Also make sure to dbt build any models that are resulting in that error before you run dbt docs generate.

1reaction
dduran28commented, Jul 8, 2022

@lewisosborne I was running into the same issue, I bypassed it by deleting that ephemeral tag at the top and then re-running dbt docs generate and then the subsequent dbt2looker command. That gets me passed the initial error highlighted here.

I am running into a different error afterwards where I am seeing not supported for conversion from redshift to looker for all of my data types but maybe we can tackle that one separately.

Let me know if my initial suggestion gets you past the issue with the ephemeral model.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Project Parsing | dbt Developer Hub
Parsing projects can be slow, especially as projects get bigger—hundreds of models, thousands of files—which is frustrating in development.
Read more >
[CT-337] [Bug] dbt fails with the only error message being ...
After having seen some messages in the debug log about partial parsing, we did a dbt clean which then showed us an error...
Read more >
In dbt, when I add a well formatted .yml file to my project, I stop ...
Sequence of the issue: I created .sql files in my models folder and subfolders, compiled them, ran dbt, and they showed up in...
Read more >
Orchestrate dbt with Airflow | Astronomer Documentation
Organizations can use Airflow to orchestrate and execute dbt models as DAGs. ... However, running dbt at the project-level has several issues:.
Read more >
A rant against dbt ref - Max Halford
Rant aside, the real problem with the ref function is that you can still write your queries without it. The issue is that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found