Skip to content

Commit 9f88779

Browse files
authored
Fix incorrect code samples in the Deadline Alerts docs (#70709)
1 parent 77838ed commit 9f88779

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎airflow-core/docs/howto/deadline-alerts.rst‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,17 +447,19 @@ implement an ``_evaluate_with()`` method.
447447
class MyQueuedReference(BaseDeadlineReference):
448448
"""A custom reference evaluated when Dag runs are queued."""
449449
450-
required_kwargs = {"custom_param"}
450+
# Ask for the Dag run context values supplied by Airflow; see notes below.
451+
required_kwargs = {"dag_id", "run_id"}
451452
452453
def _evaluate_with(self, *, session: Session, **kwargs) -> datetime:
453-
custom_value = kwargs["custom_param"]
454-
# Use custom_value in your calculation
454+
dag_id = kwargs["dag_id"]
455+
run_id = kwargs["run_id"]
456+
# Use dag_id and run_id in your calculation
455457
return your_datetime
456458
457459
458460
**Using a Custom Reference in a Dag**
459461

460-
Once registered [see notes below], use your custom references in Dag definitions like any other reference:
462+
Once registered, use your custom references in Dag definitions like any other reference:
461463

462464
.. code-block:: python
463465
@@ -467,7 +469,7 @@ Once registered [see notes below], use your custom references in Dag definitions
467469
with DAG(
468470
dag_id="custom_reference_example",
469471
deadline=DeadlineAlert(
470-
reference=DeadlineReference.MyCustomDecoratedReference(),
472+
reference=DeadlineReference.MyCustomDecoratedReference,
471473
interval=timedelta(hours=2),
472474
callback=AsyncCallback(my_callback),
473475
),
@@ -522,5 +524,8 @@ followed by a more urgent escalation if the Dag is still running.
522524
* **Timezone Awareness**: Always return timezone-aware datetime objects.
523525
* **Plugin Placement**: One convenient place for custom references is in the plugins directory.
524526
* **API Server Restart**: Restart the Airflow API Server after adding or modifying custom references.
525-
* **Required Parameters**: Use ``required_kwargs`` to specify parameters your reference needs.
527+
* **Required Parameters**: ``required_kwargs`` declares which Dag run context values Airflow should
528+
forward to ``_evaluate_with()``. Only ``dag_id`` and ``run_id`` are available; declaring anything
529+
else raises a ``ValueError`` when the deadline is evaluated. To configure a reference itself, give
530+
it constructor fields or read from an Airflow Variable.
526531
* **Database Access**: Use the ``session`` parameter for Airflow database queries if needed.

0 commit comments

Comments
 (0)