Skip to content

[Bug] Click 8.2+ deprecation warning #12038

@edgarrmondragon

Description

@edgarrmondragon

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

Starting with Click 8.2, OptionParser is deprecated. It's used in a single location in the codebase:

from click.parser import OptionParser, ParsingState

def add_to_parser(self, parser: OptionParser, ctx: Context):

Expected Behavior

No deprecation warnings are raised when running dbt.

Steps To Reproduce

Run dbt with the PYTHONWARNINGS=error env var set:

PYTHONWARNINGS=error dbt --help

Relevant log output

$ PYTHONWARNINGS=error dbt --help
Traceback (most recent call last):
  File "/repro/dbt-labs/dbt-core/.venv/bin/dbt", line 4, in <module>
    from dbt.cli.main import cli
  File "/repro/dbt-labs/dbt-core/core/dbt/cli/__init__.py", line 1, in <module>
    from .main import cli as dbt_cli  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/repro/dbt-labs/dbt-core/core/dbt/cli/main.py", line 14, in <module>
    from dbt.cli import params as p
  File "/repro/dbt-labs/dbt-core/core/dbt/cli/params.py", line 13, in <module>
    from dbt.cli.options import MultiOption
  File "/repro/dbt-labs/dbt-core/core/dbt/cli/options.py", line 6, in <module>
    from click.parser import OptionParser, ParsingState
  File "/repro/dbt-labs/dbt-core/.venv/lib/python3.13/site-packages/click/parser.py", line 513, in __getattr__
    warnings.warn(
    ~~~~~~~~~~~~~^
        f"'parser.{name}' is deprecated and will be removed in Click 9.0."
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        stacklevel=2,
        ^^^^^^^^^^^^^
    )
    ^
DeprecationWarning: 'parser.OptionParser' is deprecated and will be removed in Click 9.0. The old parser is available in 'optparse'.

Environment

- OS: macOS 15.6
- Python: 3.13.7
- dbt: 1.10.12

Which database adapter are you using with dbt?

other (mention it in "Additional Context")

Additional Context

Using dbt with dbt-duckdb, though this problem is independent of the adapter used.


To be fair, the class will only be removed in 9.0, and dbt currently constrains click to <9.0 so this is not going to break any time soon,

"click>=8.0.2,<9.0",

but an annoying warning is still displayed.

I think the warning can be easily addressed at run time by making those click imports type-checking only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions