dbt-core: [CT-2672] [Bug] Cannot import name 'Unpack' from 'typing_extensions' (dbt-core 1.5.1)
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
I’m trying to migrate to dbt-core 1.5.1 and play with programmatic invocations
Expected Behavior
can import and use dbtRunner, dbtRunnerResult from python environment
Steps To Reproduce
- pip install -r requirements.txt (see in the bellow section)
from dbt.cli.main import dbtRunner, dbtRunnerResult
# initialize
dbt_runner = dbtRunner()
cli_args = ["run", "--select", "tag:my_tag"]
# run the command
res: dbtRunnerResult = dbt_runner.invoke(cli_args)
# inspect the results
for r in res.result:
print(f"{r.node.name}: {r.status}")
Relevant log output
ImportError Traceback (most recent call last)
<command-1597366681957068> in <cell line: 1>()
----> 1 from dbt.cli.main import dbtRunner, dbtRunnerResult
2
3 def dbt(args):
4 # initialize
5 dbt_runner = dbtRunner()
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/dbt/cli/__init__.py in <module>
----> 1 from .main import cli as dbt_cli # noqa
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/dbt/cli/main.py in <module>
11 )
12
---> 13 from dbt.cli import requires, params as p
14 from dbt.cli.exceptions import (
15 DbtInternalException,
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/dbt/cli/requires.py in <module>
----> 1 import dbt.tracking
2 from dbt.version import installed as installed_version
3 from dbt.adapters.factory import adapter_management, register_adapter
4 from dbt.flags import set_flags, get_flag_dict
5 from dbt.cli.exceptions import (
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/dbt/tracking.py in <module>
13 from snowplow_tracker import logger as sp_logger
14
---> 15 from dbt import version as dbt_version
16 from dbt.clients.yaml_helper import safe_load, yaml # noqa:F401
17 from dbt.events.functions import fire_event, get_invocation_id
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/dbt/version.py in <module>
8 import requests
9
---> 10 import dbt.exceptions
11 import dbt.semver
12
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/dbt/exceptions.py in <module>
6 from typing import Any, Dict, List, Mapping, Optional, Union
7
----> 8 from dbt.dataclass_schema import ValidationError
9 from dbt.events.helpers import env_secrets, scrub_secrets
10 from dbt.node_types import NodeType
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/dbt/dataclass_schema.py in <module>
13
14 # type: ignore
---> 15 from mashumaro import DataClassDictMixin
16 from mashumaro.config import TO_DICT_ADD_OMIT_NONE_FLAG, BaseConfig as MashBaseConfig
17 from mashumaro.types import SerializableType, SerializationStrategy
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/mashumaro/__init__.py in <module>
----> 1 from mashumaro.exceptions import MissingField
2 from mashumaro.helper import field_options, pass_through
3 from mashumaro.mixins.dict import DataClassDictMixin
4
5 __all__ = [
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/mashumaro/exceptions.py in <module>
1 from typing import Any, Optional, Type
2
----> 3 from mashumaro.core.meta.helpers import type_name
4
5
/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
169 # Import the desired module. If you’re seeing this while debugging a failed import,
170 # look at preceding stack frames for relevant error information.
--> 171 original_result = python_builtin_import(name, globals, locals, fromlist, level)
172
173 is_root_import = thread_local._nest_level == 1
/local_disk0/.ephemeral_nfs/envs/pythonEnv-8dd839ed-b379-4ba3-b2af-457367cb74b7/lib/python3.9/site-packages/mashumaro/core/meta/helpers.py in <module>
23
24 import typing_extensions
---> 25 from typing_extensions import Unpack
26
27 from mashumaro.core.const import (
ImportError: cannot import name 'Unpack' from 'typing_extensions' (/databricks/python/lib/python3.9/site-packages/typing_extensions.py)
Environment
- OS: Linux 5.15.0-1035-aws
- Python: 3.9.5
- dbt: dbt-core==1.5.1
Content of requirements.txt
dbt-core==1.5.1
dbt-databricks==1.5.2
dbt-spark==1.5.0
dbt-spark[PyHive]==1.5.0
sqlfluff==2.1.1
sqlfluff-templater-dbt==2.1.1
databricks-sql-cli==0.3.2
dryable==1.1.0
tqdm==4.64.0
elementary-data==0.8.0
elementary-data[databricks]==0.8.0
requests
types-protobuf==4.23.0.1 # added to play around it
typing_extensions==4.4.0 # the same result with 4.4.6
Which database adapter are you using with dbt?
spark
Additional Context
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 38 (19 by maintainers)
I can file a ticket; I work on the adapter specifically, so I don’t have a lot of insight into the DBR.
Oh, I’ve come across something like this after typing-extensions upgrade and made a fix in this commit:
It will be included in the upcoming release this or next week.
Hi, any updates on this issue? We are running into the same thing. We are implementing Programmatic Invocation here as well and have big plans for it! To isolate this problem I use this small bit of Python code and simply run it from the Databricks Workspace on a cluster that only has dbt-databricks 1.6.6 installed:
I have tested it with different LTS Databricks runtime versions (12.2 and 13.3), different Access modes (Shared and Single) and with or without installing typing_extenstions 4.7.1. All using dbt-databricks 1.6.6. These are the results:
My complete stack trace when I get the error looks like this:
I got the same issue when running on Databricks Runtime 13.3 LTS. But on Databricks Runtime 12.2 LTS it worked out fine. I did not try to fix
typing_extensions==4.7.1as you did but rather tried to update to the newest version oftyping_extensionswhich did not make it work.This was tried with dbt-core 1.6.2 and dbt-databricks 1.6.4 + 1.6.5.
Here my full stack trace for further investigation for the devs:
Hope that helps to fix this issue.
@dbeatty10
I think it’s worth to exclude only those versions that break something in dbt-core. Not taking into account the transition to major version 3, I remember that 3.0.2 and 3.1.0 were problematic, so they are candidates for exclusion. On the other hand if you rely on some functionality that exists only from a version X then you should obviously pin that version as the minimal one and remove all exclusions before X as redundant:
If I were in your place, I would be looking at pull requests from dependabot and either: a) exclude package versions not passing the tests leaving the minimal version X b) bump the minimal version X to the following patch version that passes the tests
The option “a” is better for users because it makes it easier to use dbt-core in combination with other packages that may also depend on mashumaro. But if dbt-core is positioned as the product rather than as a library than option “b” or even strict pin to the specific version of a package is also a good choice.
@thijs-nijhuis-shell sounds good, thanks. If there’s some weird interaction on those warnings that turns out to be something we need to fix on the dbt side please do open a separate issue. Hopefully you can get an update that makes those warnings stop.
@tlento , thanks for fixing it for 1.7.x as well and all the effort you put into this.
Unfortunately, my workaround to suppress the warnings doesn’t work after all. When promoting the warnings to errors the dbt library is not loaded (completely) which makes sense of course. For some reason, when I set the warnings to ‘ignore’ instead of error like the python documentation says the warnings are still shown. I have no idea how to solve or workaround this.
The link you added about 13.3 runtime points to 13.3LTS ML. We use 13.3LTS and that one doesn’t have the
wraptpackage installed it seems. I also don’t see it when doing the deptreelist.I also don’t get the warning (or the error that is solved now) when running locally. I am going to create a Issue in the dbt-databricks github for this.
dbt-semantic-interfaces 0.2.3 has been deployed: https://pypi.org/project/dbt-semantic-interfaces/0.2.3/
At this point, doing a pip upgrade (for existing installations) or doing a fresh install of dbt-core 1.6 or a corresponding adapter package should pin the typing-extensions version to something past 4.4.0.
As mentioned earlier, this will NOT fix issues with 1.5 installs, and even on 1.6 any installation that clobbers the typing_extensions version may still cause problems, but at least if you install dbt-core it should now update typing-extensions appropriately.
Thanks to @Fatal1ty for submitting the quick patch on the DSI side and everyone here (and especially @thijs-nijhuis-shell ) for the detailed info on what was broken.
Thanks! I will make sure to test it on our end when available.
@QMalcolm and I have done some further digging, and this comment https://github.com/dbt-labs/dbt-core/issues/7828#issuecomment-1780640653 was extremely helpful in our investigation, so big thanks to @thijs-nijhuis-shell
What appears to be happening is Databricks in particular is configuring its initial python environment with typing-extensions set to 4.1/4.3, and a subsequent install of dbt-core 1.6 will not update this because 1.6 is set to require ~=4.0 (by way of dbt-semantic-interfaces).
Since everything works if you install dbt-core (or typing-extensions 4.7.1) first, this suggests databricks is actually perfectly happy with 4.7 or whatever.
However, that databricks 13.3 overwrites the typing-extensions module with 4.3 (while 12.2 leaves that well enough alone) is a bit of a cause for concern. Like, why would it do that?
We’re ready to backport the dbt-semantic-interfaces change to address the issue with 1.6, but we’d like to confirm that Databricks 13.3 is happy with a later version of typing_extensions before we merge and deploy. We’ll update here once we’re done.
@Almaz-Murzabekov I guess this should not be required when you install packages with the %pip magic or the init cluster script.
The root cause of this issue comes from dbt-semantic-interfaces:
Hey @thijs-nijhuis-shell, I don’t know your setup in Databricks, but if you’re using code inside dbx notebooks, please also try this command before running any dbt-api call (restarting python process)
TBH, dunno why, but it’s required if you’re installing deps inside the notebook
@thijs-nijhuis-shell I guess it would be helpful if you could find out for each runtime / mode what version of package
typing_extensionsis used. e.g. runpip freeze | grep typing_extensionsand put the version number in a table as given above. Maybe the python version would help as well (python --version). I guess we should boil that down since here we are in the dbt-core repo, not the Databricks repo.