You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "wjddn279 (via GitHub)" <gi...@apache.org> on 2026/02/09 12:51:15 UTC

[PR] fix timetable serialization error when decoding relative delta [airflow]

wjddn279 opened a new pull request, #61671:
URL: https://github.com/apache/airflow/pull/61671

   related: https://apache-airflow.slack.com/archives/CCQ7EGB1P/p1770622588017049
   
   ## Problem
   
   When using the following relative syntax, the dag-processor crashes if weekday is used.
   ```python
   dag = DAG(
       dag_id=dag_id,
       default_args=default_args,
       description=f'dynamic_dag_id',
       schedule=relativedelta(weekday=SU) # problem
   )
   ```
   ```bash
   File "/home/airflow/.local/lib/python3.12/site-packages/airflow/serialization/serialized_objects.py", line 4000, in timetable
       return decode_timetable(self.data["dag"]["timetable"])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/home/airflow/.local/lib/python3.12/site-packages/airflow/serialization/serialized_objects.py", line 459, in decode_timetable
       return timetable_class.deserialize(var[Encoding.VAR])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/home/airflow/.local/lib/python3.12/site-packages/airflow/timetables/trigger.py", line 154, in deserialize
       _deserialize_interval(data["delta"]),
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/home/airflow/.local/lib/python3.12/site-packages/airflow/timetables/trigger.py", line 51, in _deserialize_interval
       return decode_relativedelta(value)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/home/airflow/.local/lib/python3.12/site-packages/airflow/serialization/serialized_objects.py", line 179, in decode_relativedelta
       var["weekday"] = relativedelta.weekday(*var["weekday"])
   ```
   
   ## Why?
   
   The root cause is that the initial state of the timetable in serialized dag is `'timetable': {'__type': 'airflow.timetables.trigger.DeltaTriggerTimetable', '__var': {'delta': {'weekday': [6]}, 'interval': 0.0}}`, but during the serialization process, the value gets modified when the function `decode_relativedelta` is called. The modified value becomes `'timetable': {'__type': 'airflow.timetables.trigger.DeltaTriggerTimetable', '__var': {'delta': {'weekday': SU}, 'interval': 0.0}`, where it's updated to an object value.
   
   ## Solution
   
   Fixed by using `deepcopy` to prevent modification of the original value (serialized dag).
   
   ## 
   
   
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull request.
   Write a good git commit message following this guide: http://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the documentation.
   
   Feel free to ping (in general) for the review if you do not see reaction for a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
   -->
   
   - [ ] Yes (please specify the tool below)
   
   <!--
   Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "bolkedebruin (via GitHub)" <gi...@apache.org>.
bolkedebruin merged PR #61671:
URL: https://github.com/apache/airflow/pull/61671


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "wjddn279 (via GitHub)" <gi...@apache.org>.
wjddn279 commented on code in PR #61671:
URL: https://github.com/apache/airflow/pull/61671#discussion_r2791041388


##########
airflow-core/src/airflow/serialization/decoders.py:
##########
@@ -56,9 +57,10 @@
 
 def decode_relativedelta(var: dict[str, Any]) -> dateutil.relativedelta.relativedelta:
     """Dencode a relativedelta object."""
-    if "weekday" in var:
-        var["weekday"] = dateutil.relativedelta.weekday(*var["weekday"])
-    return dateutil.relativedelta.relativedelta(**var)
+    copy_var = deepcopy(var)
+    if "weekday" in copy_var:
+        copy_var["weekday"] = dateutil.relativedelta.weekday(*copy_var["weekday"])
+    return dateutil.relativedelta.relativedelta(**copy_var)

Review Comment:
   done. make it shallow copy



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "wjddn279 (via GitHub)" <gi...@apache.org>.
wjddn279 commented on code in PR #61671:
URL: https://github.com/apache/airflow/pull/61671#discussion_r2785423065


##########
airflow-core/src/airflow/serialization/decoders.py:
##########
@@ -56,9 +57,10 @@
 
 def decode_relativedelta(var: dict[str, Any]) -> dateutil.relativedelta.relativedelta:
     """Dencode a relativedelta object."""
-    if "weekday" in var:
-        var["weekday"] = dateutil.relativedelta.weekday(*var["weekday"])
-    return dateutil.relativedelta.relativedelta(**var)
+    copy_var = deepcopy(var)
+    if "weekday" in copy_var:
+        copy_var["weekday"] = dateutil.relativedelta.weekday(*copy_var["weekday"])
+    return dateutil.relativedelta.relativedelta(**copy_var)

Review Comment:
   I attach the full log. This occurs when running `breeze start-airflow` on the current main branch with the following DAG placed in the DAGs path.  
   [0925.txt](https://github.com/user-attachments/files/25198001/0925.txt)
   [test_dag.py](https://github.com/user-attachments/files/25198008/test_dag.py)
   
   I've confirmed that after the fix, it parses successfully with `breeze start-airflow`. (Feel free to try it yourself.) As mentioned in the description, serialization itself works correctly, but the value gets unintentionally mutated during function execution. `{'weekday': [6]}` -> `{'weekday': SU}`
   
   To explain in more detail: the function is executed continuously every time the [timetable property](https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/serialization/serialized_objects.py#L2270) is called. On the first execution, {'weekday': [6]} is passed correctly, but the value gets mutated to `{'weekday': SU}` during this first execution, causing errors from the second execution onwards.



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "wjddn279 (via GitHub)" <gi...@apache.org>.
wjddn279 commented on PR #61671:
URL: https://github.com/apache/airflow/pull/61671#issuecomment-4037708391

   @bolkedebruin 
   
   regression test is added! thanks!


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "yevsh (via GitHub)" <gi...@apache.org>.
yevsh commented on PR #61671:
URL: https://github.com/apache/airflow/pull/61671#issuecomment-3876693671

   @wjddn279 
   
   FYI such DAG,
   
   ` schedule=relativedelta(month=1,minute=1,weekday=SU,years=+1),`
   
   worked in Airflow 2.10.5
   
   But broke after upgrade to  3.1.5


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "wjddn279 (via GitHub)" <gi...@apache.org>.
wjddn279 commented on PR #61671:
URL: https://github.com/apache/airflow/pull/61671#issuecomment-3931651636

   @uranusjr 
   
   Can you review it again please? 


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "yevsh (via GitHub)" <gi...@apache.org>.
yevsh commented on PR #61671:
URL: https://github.com/apache/airflow/pull/61671#issuecomment-3875743502

   Hi,  I am the one that asked to fix this issue.
   I tried to run locally the above `decode_relativedelta`
   
   passing to it 
   ```
   data = {
       "weekday": SU
   }
   ```
   
   dateutil._common.weekday() argument after * must be an iterable, not weekday
   
   maybe should check 
   
    ` if  isinstance(var["weekday"], dateutil._common.weekday):`
   
   and then not to unpack it as use 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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "bolkedebruin (via GitHub)" <gi...@apache.org>.
bolkedebruin commented on PR #61671:
URL: https://github.com/apache/airflow/pull/61671#issuecomment-4034408926

   Please add a test that fails with the previous version and succeeds now


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "wjddn279 (via GitHub)" <gi...@apache.org>.
wjddn279 commented on PR #61671:
URL: https://github.com/apache/airflow/pull/61671#issuecomment-4022972256

   @uranusjr @ashb @bolkedebruin @kaxil 
   
   Kindly ping code owners and reviewers!
   There's some users want to resolve the issue by this pr and problem is very clear


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #61671:
URL: https://github.com/apache/airflow/pull/61671#discussion_r2785926513


##########
airflow-core/src/airflow/serialization/decoders.py:
##########
@@ -56,9 +57,10 @@
 
 def decode_relativedelta(var: dict[str, Any]) -> dateutil.relativedelta.relativedelta:
     """Dencode a relativedelta object."""
-    if "weekday" in var:
-        var["weekday"] = dateutil.relativedelta.weekday(*var["weekday"])
-    return dateutil.relativedelta.relativedelta(**var)
+    copy_var = deepcopy(var)
+    if "weekday" in copy_var:
+        copy_var["weekday"] = dateutil.relativedelta.weekday(*copy_var["weekday"])
+    return dateutil.relativedelta.relativedelta(**copy_var)

Review Comment:
   Shallow copy is sufficient here.
   
   ```suggestion
       copy_var = {**var, "weekday": dateutil.relativedelta.weekday(*copy_var["weekday"])}
       return dateutil.relativedelta.relativedelta(**copy_var)
   ```



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "SameerMesiah97 (via GitHub)" <gi...@apache.org>.
SameerMesiah97 commented on code in PR #61671:
URL: https://github.com/apache/airflow/pull/61671#discussion_r2785111835


##########
airflow-core/src/airflow/serialization/decoders.py:
##########
@@ -56,9 +57,10 @@
 
 def decode_relativedelta(var: dict[str, Any]) -> dateutil.relativedelta.relativedelta:
     """Dencode a relativedelta object."""
-    if "weekday" in var:
-        var["weekday"] = dateutil.relativedelta.weekday(*var["weekday"])
-    return dateutil.relativedelta.relativedelta(**var)
+    copy_var = deepcopy(var)
+    if "weekday" in copy_var:
+        copy_var["weekday"] = dateutil.relativedelta.weekday(*copy_var["weekday"])
+    return dateutil.relativedelta.relativedelta(**copy_var)

Review Comment:
   I am not sure preventing mutation of the original "weekday" object will fix the bug you identified. Looks like the root cause might be incomplete serialization of the weekday object might be the cause here. It seems like the second parameter for the weekday object (nth) might have not been captured during serialization. I understand that it's an optional parameter with a `None` default but it's still part of the object's identity. So this may result in the "weekday" object being partially resolved. 



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] fix timetable serialization error when decoding relative delta [airflow]

Posted by "wjddn279 (via GitHub)" <gi...@apache.org>.
wjddn279 commented on PR #61671:
URL: https://github.com/apache/airflow/pull/61671#issuecomment-3876453893

   @yevsh 
   
   The problem is that such argument values are being passed to the function in the first place. If it were serialized correctly, this case wouldn't occurs. I think this is an unnecessary guard logic.


-- 
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-unsubscribe@airflow.apache.org

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