datnguye / dbterd

Generate the ERD as a code from dbt artifacts
https://dbterd.datnguyen.de/
MIT License
198 stars 28 forks source link

[BUG] Error invoking CLI: `ImportError: cannot import name 'NotImplementedType' from 'types' #96

Closed ReubenFrankel closed 5 months ago

ReubenFrankel commented 5 months ago

Describe the bug I get the following error invoking the dbterd CLI:

Traceback (most recent call last):
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/bin/dbterd", line 5, in <module>
    from dbterd.main import main
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/main.py", line 1, in <module>
    from dbterd.cli import main as cli
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/cli/main.py", line 6, in <module>
    from dbterd.adapters.base import Executor
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/adapters/base.py", line 3, in <module>
    from types import NotImplementedType
ImportError: cannot import name 'NotImplementedType' from 'types' (/home/linuxbrew/.linuxbrew/opt/python@3.9/lib/python3.9/types.py)

To Reproduce Steps to reproduce the behavior:

python3.9 -m venv .venv
source .venv/bin.activate
pip install dbterd==1.12.0
dbterd --help

Expected behavior To be able to use the CLI.

Desktop

Additional context I also tried 1.11.0

Traceback (most recent call last):
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/bin/dbterd", line 5, in <module>
    from dbterd.main import main
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/main.py", line 1, in <module>
    from dbterd.cli import main as cli
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/cli/main.py", line 6, in <module>
    from dbterd.adapters.base import Executor
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/adapters/base.py", line 9, in <module>
    from dbterd.adapters.dbt_cloud.administrative import DbtCloudArtifact
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/adapters/dbt_cloud/administrative.py", line 4, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

After installing requests manually

Traceback (most recent call last):
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/bin/dbterd", line 5, in <module>
    from dbterd.main import main
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/main.py", line 1, in <module>
    from dbterd.cli import main as cli
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/cli/main.py", line 6, in <module>
    from dbterd.adapters.base import Executor
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/adapters/base.py", line 9, in <module>
    from dbterd.adapters.dbt_cloud.administrative import DbtCloudArtifact
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/adapters/dbt_cloud/administrative.py", line 6, in <module>
    from dbterd.helpers import file
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbterd/helpers/file.py", line 5, in <module>
    from dbt_artifacts_parser import parser
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbt_artifacts_parser/parser.py", line 20, in <module>
    from dbt_artifacts_parser.parsers.manifest.manifest_v1 import ManifestV1
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/dbt_artifacts_parser/parsers/manifest/manifest_v1.py", line 17, in <module>
    class ManifestMetadata(BaseParserModel):
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 178, in __new__
    set_model_fields(cls, bases, config_wrapper, types_namespace)
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 452, in set_model_fields
    fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map)
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/pydantic/_internal/_fields.py", line 122, in collect_model_fields
    type_hints = get_cls_type_hints_lenient(cls, types_namespace)
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 212, in get_cls_type_hints_lenient
    hints[name] = eval_type_lenient(value, globalns, localns)
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 224, in eval_type_lenient
    return eval_type_backport(value, globalns, localns)
  File "/home/reuben/.cache/pypoetry/virtualenvs/dbterd-ext-IFoOWQ5l-py3.9/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 240, in eval_type_backport
    return typing._eval_type(  # type: ignore
  File "/home/linuxbrew/.linuxbrew/opt/python@3.9/lib/python3.9/typing.py", line 292, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.9/lib/python3.9/typing.py", line 554, in _evaluate
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
TypeError: constr() got an unexpected keyword argument 'regex'
datnguye commented 5 months ago

Thanks @ReubenFrankel for finding it!

I can reproduce it now with v1.12 -- will fix it soon 🏃

For the v1.11, I think I have not fully tested it when it stands alone, but it should be working with installing dbt-core -- so a workaround here:

pip install dbt-core
pip install dbterd=1.11.1

I will tackle this together and provide patches for all impacted version soon 🏃

ReubenFrankel commented 5 months ago

Is there a reason that dbt-core is not a defined dependency?

datnguye commented 5 months ago

Hey @ReubenFrankel yes, dbterd is originally designed to understand dbt artifact files and produce the ERD code. It doesn’t call any APIs from dbt package, it hence should not depend on dbt pip package.

ReubenFrankel commented 5 months ago

@datnguye Ah, I see you were suggesting it as a workaround. What about requests as in above example? I don't use dbt Cloud so that functionality isn't required, though I'm wondering if it makes more sense as a package extra for those that do.

datnguye commented 5 months ago

@ReubenFrankel yeah I will add an extra deps with ‘requests’ for sure, and I need to fully verify all python versions to understand the case.

datnguye commented 5 months ago

It should be fixed in 1.12.2 now 🙌

Sorry for any inconveniences with this issues!