bugraoz93 commented on PR #55282:
URL: https://github.com/apache/airflow/pull/55282#issuecomment-3263893616

   > Datetime handling sometimes make Python complex :-D
   
   Exactly :D There are three layers in the code manipulating the datetime. The 
actual problem lies in the handling of datetime by httpClient and the Pydantic 
model during `model_dump`. 
   
   > I am wondering a bit that you need to parse JSON after Pydantic model 
dump() - I thought that is the reason for Pydantic - but if it is needed, I 
trust you checked for this.
   
   I thought the same and trusted the Pydantic `model_dump()` method. I assumed 
the main was working until I started doing regression tests on beta 1 :D The 
`model_dump()` in Pydantic should be able to handle datetime manipulation 
compatible with clients. What happened is that httpClient couldn't convert the 
date to JSON after `model_dump()`
   Implementation in main 
   ```python
       self.response = self.client.post(f"dags/{dag_id}/dagRuns", 
trigger_dag_run.model_dump())
   ```
   This threw a datetime JSON that is not serializable exception because the 
`model_dump` method, when creating the model dict, could not be serialised by 
the httpClient.
   
   So I tried with `model_dump_json()` in Pydantic, which returns a JSON 
string, but httpClient needs a dictionary, made the code as below.
   
   ```python
       self.response = self.client.post(
           f"dags/{dag_id}/dagRuns", 
json=json.loads(trigger_dag_run.model_dump_json())
      )
   ```
   
   It ended up in a method so that other operations using datetime or will use 
datetime in the future should do this, not a good manipulation of the models. 
Even though I didn't like the manipulation, let's keep it until I dig this deep 
and find a more elegant way of solving it :)
   
   
   


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to