ephraimbuddy commented on a change in pull request #17122:
URL: https://github.com/apache/airflow/pull/17122#discussion_r674561315



##########
File path: airflow/api_connexion/schemas/dag_run_schema.py
##########
@@ -57,21 +60,43 @@ class Meta:
     run_id = auto_field(data_key='dag_run_id')
     dag_id = auto_field(dump_only=True)
     execution_date = auto_field(validate=validate_istimezone)
+    schedule_date = fields.Method(serialize="get_schedule_date", 
deserialize="load_schedule_date")
     start_date = auto_field(dump_only=True)
     end_date = auto_field(dump_only=True)
     state = DagStateField(dump_only=True)
     external_trigger = auto_field(default=True, dump_only=True)
     conf = ConfObject()
 
+    @staticmethod
+    def get_schedule_date(obj: DagRun):
+        return obj.execution_date
+
+    def load_schedule_date(self, value: str):
+        # Use the execution_date logic to load schedule_date.
+        return self.execution_date.deserialize(value, "schedule_date", 
{"schedule_date": value})
+
     @pre_load
     def autogenerate(self, data, **kwargs):
-        """Auto generate run_id and execution_date if they are not loaded"""
-        if "execution_date" not in data.keys():
-            data["execution_date"] = str(timezone.utcnow())
-        if "dag_run_id" not in data.keys():
+        """Auto generate run_id, schedule_date, and execution_date if they are 
not loaded"""
+        # Try to fill schedule_date and execution_date if the other is 
provided.
+        schedule_date = data.get("schedule_date", _MISSING)
+        execution_date = data.get("execution_date", _MISSING)
+        if schedule_date is execution_date is _MISSING:  # Both missing.
+            data["schedule_date"] = data["execution_date"] = 
str(timezone.utcnow())
+        elif schedule_date is _MISSING:  # Only schedule_date missing.
+            data["schedule_date"] = data["execution_date"]
+        elif execution_date is _MISSING:  # Only execution_date missing.
+            data["execution_date"] = data["schedule_date"]
+        elif schedule_date != execution_date:  # Both provided but don't match.
+            raise BadRequest(
+                "schedule_date conflicts with executrion_date",

Review comment:
       ```suggestion
                   "schedule_date conflicts with execution_date",
   ```




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