PydanticUserError: 在Airflow数据库初始化命令中检测到了未注释的属性

huangapple go评论214阅读模式
英文:

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:
* &#39;orm_mode&#39; has been renamed to &#39;from_attributes&#39;
/home/ugur/aflow/venv/lib/python3.10/site-packages/pydantic/_internal/_config.py:261 UserWarning: Valid config keys have changed in V2:
* &#39;orm_mode&#39; has been renamed to &#39;from_attributes&#39;
Traceback (most recent call last):
File &quot;/home/ugur/aflow/venv/bin/airflow&quot;, line 8, in &lt;module&gt;
sys.exit(main())
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/__main__.py&quot;, line 48, in main
args.func(args)
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/cli/cli_config.py&quot;, line 51, in command
func = import_string(import_path)
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/utils/module_loading.py&quot;, line 36, in import_string
module = import_module(module_path)
File &quot;/usr/local/lib/python3.10/importlib/__init__.py&quot;, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1050, in _gcd_import
File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1027, in _find_and_load
File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1006, in _find_and_load_unlocked
File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 688, in _load_unlocked
File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 883, in exec_module
File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 241, in _call_with_frames_removed
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/cli/commands/standalone_command.py&quot;, line 35, in &lt;module&gt;
from airflow.jobs.scheduler_job_runner import SchedulerJobRunner
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/jobs/scheduler_job_runner.py&quot;, line 58, in &lt;module&gt;
from airflow.models.serialized_dag import SerializedDagModel
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/models/serialized_dag.py&quot;, line 34, in &lt;module&gt;
from airflow.serialization.serialized_objects import DagDependency, SerializedDAG
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/serialization/serialized_objects.py&quot;, line 57, in &lt;module&gt;
from airflow.serialization.pydantic.dag_run import DagRunPydantic
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/serialization/pydantic/dag_run.py&quot;, line 24, in &lt;module&gt;
from airflow.serialization.pydantic.dataset import DatasetEventPydantic
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/airflow/serialization/pydantic/dataset.py&quot;, line 40, in &lt;module&gt;
class TaskOutletDatasetReferencePydantic(BaseModelPydantic):
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py&quot;, line 95, in __new__
private_attributes = inspect_namespace(
File &quot;/home/ugur/aflow/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py&quot;, line 328, in inspect_namespace
raise PydanticUserError(
pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `dag_id = &lt;class &#39;str&#39;&gt;`. 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[&#39;ignored_types&#39;]`.
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&gt;=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&gt;=1.10.0,&lt;2.0.0,请查看 https://github.com/apache/airflow/blob/2811ba710991d71466afa21c500ee55aeda5d8a1/setup.cfg#L131

英文:

airflow 2.6.2 has pydantic&gt;=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&gt;=1.10.0,&lt;2.0.0 see https://github.com/apache/airflow/blob/2811ba710991d71466afa21c500ee55aeda5d8a1/setup.cfg#L131

huangapple
  • 本文由 发表于 2023年7月6日 20:56:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定