potiuk commented on code in PR #70328:
URL: https://github.com/apache/airflow/pull/70328#discussion_r3887415518


##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -503,8 +503,13 @@ def trigger(
         """Create a Dag run."""
         if trigger_dag_run.conf is None:
             trigger_dag_run.conf = {}
+        # partition_key and bundle_version were added in Airflow 3.2.0; older 
API
+        # servers (extra="forbid") reject them as unrecognized fields even 
when null.
+        # logical_date must stay in the body even when None - the server 
declares it
+        # without a default, making it a required (though nullable) field.
         self.response = self.client.post(
-            f"dags/{dag_id}/dagRuns", 
json=trigger_dag_run.model_dump(mode="json")
+            f"dags/{dag_id}/dagRuns",
+            json=trigger_dag_run.model_dump(mode="json", 
exclude={"partition_key", "bundle_version"}),

Review Comment:
   Excluding these unconditionally means they can never be sent, including to 
servers that support them — and both are user-settable today 
(`cli_config.py:714` generates a CLI flag for every model field bar `schema_`), 
so `--partition-key foo` is silently discarded rather than rejected.
   
   Conditioning the exclusion on the value keeps both sides working:
   
   ```suggestion
           exclude = {
               field
               for field in ("partition_key", "bundle_version")
               if getattr(trigger_dag_run, field) is None
           }
           self.response = self.client.post(
               f"dags/{dag_id}/dagRuns",
               json=trigger_dag_run.model_dump(mode="json", exclude=exclude),
           )
   ```
   
   An old server no longer sees the unknown null fields; a new server still 
receives values the user actually set. A user who sets `--partition-key` 
against an old server then gets a 422, which is the correct outcome — that 
server genuinely cannot honour the request, and saying so is better than 
pretending it worked.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting



-- 
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]

Reply via email to