PydanticUserError:在 Airflow db init 命令中检测到未注释的属性

问题描述 投票:0回答:2

我尝试在 Airflow 项目中运行

airflow db init
命令,但遇到以下错误:

(venv) ➜  aflow airflow standalone

/home/ugur/aflow/venv/lib/python3.10/site-packages/pydantic/_internal/_config.py:261 UserWarning: Valid config keys have changed in V2:
* 'orm_mode' has been renamed to 'from_attributes'
/home/ugur/aflow/venv/lib/python3.10/site-packages/pydantic/_internal/_config.py:261 UserWarning: Valid config keys have changed in V2:
* 'orm_mode' has been renamed to 'from_attributes'
Traceback (most recent call last):
  File "/home/ugur/aflow/venv/bin/airflow", line 8, in <module>
    sys.exit(main())
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/__main__.py", line 48, in main
    args.func(args)
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/cli/cli_config.py", line 51, in command
    func = import_string(import_path)
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/utils/module_loading.py", line 36, in import_string
    module = import_module(module_path)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/cli/commands/standalone_command.py", line 35, in <module>
    from airflow.jobs.scheduler_job_runner import SchedulerJobRunner
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/jobs/scheduler_job_runner.py", line 58, in <module>
    from airflow.models.serialized_dag import SerializedDagModel
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/models/serialized_dag.py", line 34, in <module>
    from airflow.serialization.serialized_objects import DagDependency, SerializedDAG
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/serialization/serialized_objects.py", line 57, in <module>
    from airflow.serialization.pydantic.dag_run import DagRunPydantic
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/serialization/pydantic/dag_run.py", line 24, in <module>
    from airflow.serialization.pydantic.dataset import DatasetEventPydantic
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/serialization/pydantic/dataset.py", line 40, in <module>
    class TaskOutletDatasetReferencePydantic(BaseModelPydantic):
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 95, in __new__
    private_attributes = inspect_namespace(
  File "/home/ugur/aflow/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 328, in inspect_namespace
    raise PydanticUserError(
pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `dag_id = <class 'str'>`. All model fields require a type annotation; if `dag_id` is not meant to be a field, you may be able to resolve this error by annotating it as a `ClassVar` or updating `model_config['ignored_types']`.

For further information visit https://errors.pydantic.dev/2.0.2/u/model-field-missing-annotation

如何解决这个问题?

python --版本: Python 3.10.12 气流版本: 2.6.2

python airflow virtualenv pydantic
2个回答
4
投票

airflow 2.6.2 有

pydantic>=1.10.0
作为依赖项,请参阅 https://github.com/apache/airflow/blob/2.6.2/setup.cfg#L127 pydantic 最近有一个新的主要版本 2.0.0,因为它已损坏,您可以跟踪 Github 问题https://github.com/apache/airflow/issues/32311。 同时,您可以限制pydantic版本
pydantic>=1.10.0,<2.0.0
参见https://github.com/apache/airflow/blob/2811ba710991d71466afa21c500ee55aeda5d8a1/setup.cfg#L131


0
投票

卸载 pydantic,然后使用 pip install pydantic==1.10.1 解决了我的问题

© www.soinside.com 2019 - 2024. All rights reserved.