英文:
PydanticUserError: A non-annotated attribute was detected in Airflow db init command
问题
我正在尝试在我的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 --version:
Python 3.10.12
airflow version:
2.6.2
英文:
I'm trying to run the airflow db init
command in my Airflow project, but I'm encountering the following error:
(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
How can I resolve this issue?
python --version:
Python 3.10.12
airflow version:
2.6.2
答案1
得分: 2
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
英文:
airflow 2.6.2 has pydantic>=1.10.0
as a dependency see https://github.com/apache/airflow/blob/2.6.2/setup.cfg#L127
and pydantic has a new major release 2.0.0 recently because of that it is broken you can track the Github issue https://github.com/apache/airflow/issues/32311.
meanwhile, you can restrict pydantic version pydantic>=1.10.0,<2.0.0
see https://github.com/apache/airflow/blob/2811ba710991d71466afa21c500ee55aeda5d8a1/setup.cfg#L131
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论