dstandish commented on code in PR #37854:
URL: https://github.com/apache/airflow/pull/37854#discussion_r1527572192
##########
airflow/serialization/pydantic/taskinstance.py:
##########
@@ -105,12 +105,13 @@ class TaskInstancePydantic(BaseModelPydantic,
LoggingMixin):
trigger_timeout: Optional[datetime]
next_method: Optional[str]
next_kwargs: Optional[dict]
- run_as_user: Optional[str]
+ run_as_user: Optional[str] = None
Review Comment:
the reason is you will see errors like this:
```
[2024-03-17T17:48:27.227+0000] {rpc_api_endpoint.py:135} ERROR - Error
executing method: airflow.models.dagrun.DagRun.fetch_task_instance.
[2024-03-17T17:48:27.227+0000] {rpc_api_endpoint.py:136} ERROR - 3
validation errors for TaskInstancePydantic
run_as_user
Field required [type=missing, input_value=<unprintable TaskInstance
object>, input_type=TaskInstance]
For further information visit https://errors.pydantic.dev/2.5/v/missing
task
Field required [type=missing, input_value=<unprintable TaskInstance
object>, input_type=TaskInstance]
For further information visit https://errors.pydantic.dev/2.5/v/missing
raw
Field required [type=missing, input_value=<unprintable TaskInstance
object>, input_type=TaskInstance]
For further information visit https://errors.pydantic.dev/2.5/v/missing
Traceback (most recent call last):
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/api_internal/endpoints/rpc_api_endpoint.py",
line 131, in internal_airflow_api
output_json = BaseSerialization.serialize(output,
use_pydantic_models=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/serialization/serialized_objects.py",
line 550, in serialize
mod = _pydantic_model_dump(pyd_mod, var)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/serialization/serialized_objects.py",
line 546, in _pydantic_model_dump
return model_cls.model_validate(var).model_dump(mode="json") # type:
ignore[attr-defined]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.11/site-packages/pydantic/main.py",
line 503, in model_validate
return cls.__pydantic_validator__.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 3 validation errors for
TaskInstancePydantic
run_as_user
Field required [type=missing, input_value=<unprintable TaskInstance
object>, input_type=TaskInstance]
For further information visit https://errors.pydantic.dev/2.5/v/missing
task
Field required [type=missing, input_value=<unprintable TaskInstance
object>, input_type=TaskInstance]
For further information visit https://errors.pydantic.dev/2.5/v/missing
raw
Field required [type=missing, input_value=<unprintable TaskInstance
object>, input_type=TaskInstance]
For further information visit https://errors.pydantic.dev/2.5/v/missing
```
and the reason for _that_, i think, is that these attrs are not set
initially on TaskInstance.
that's why for example you see code like this:
https://github.com/apache/airflow/blob/9d898684b26a967242e7f685058d885519b6d383/airflow/models/taskinstance.py#L3661
Should we set these in `init` on TI, instead?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]