Skip to content

Commit

Permalink
Use "note" instead of "notes" in API re dag run / task instance notes (
Browse files Browse the repository at this point in the history
…apache#27867)

* rename notes to note in endpoint code

* rename notes to note in model code

* update test code

* update react code

* fixups

* fixup! fixups

* fix rebase mistake

Co-authored-by: Ephraim Anierobi <[email protected]>
  • Loading branch information
dstandish and ephraimbuddy authored Nov 24, 2022
1 parent 80c327b commit 3b032e5
Show file tree
Hide file tree
Showing 37 changed files with 165 additions and 165 deletions.
8 changes: 4 additions & 4 deletions airflow/api_connexion/endpoints/dag_run_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def clear_dag_run(*, dag_id: str, dag_run_id: str, session: Session = NEW_SESSIO
],
)
@provide_session
def set_dag_run_notes(*, dag_id: str, dag_run_id: str, session: Session = NEW_SESSION) -> APIResponse:
def set_dag_run_note(*, dag_id: str, dag_run_id: str, session: Session = NEW_SESSION) -> APIResponse:
"""Set the note for a dag run."""
dag_run: DagRun | None = (
session.query(DagRun).filter(DagRun.dag_id == dag_id, DagRun.run_id == dag_run_id).one_or_none()
Expand All @@ -434,17 +434,17 @@ def set_dag_run_notes(*, dag_id: str, dag_run_id: str, session: Session = NEW_SE
raise NotFound(error_message)
try:
post_body = set_dagrun_note_form_schema.load(get_json_request_dict())
new_value_for_notes = post_body["notes"]
new_note = post_body["note"]
except ValidationError as err:
raise BadRequest(detail=str(err))

from flask_login import current_user

current_user_id = getattr(current_user, "id", None)
if dag_run.dag_run_note is None:
dag_run.notes = (new_value_for_notes, current_user_id)
dag_run.note = (new_note, current_user_id)
else:
dag_run.dag_run_note.content = new_value_for_notes
dag_run.dag_run_note.content = new_note
dag_run.dag_run_note.user_id = current_user_id
session.commit()
return dagrun_schema.dump(dag_run)
16 changes: 8 additions & 8 deletions airflow/api_connexion/endpoints/task_instance_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
TaskInstanceReferenceCollection,
clear_task_instance_form,
set_single_task_instance_state_form,
set_task_instance_notes_form_schema,
set_task_instance_note_form_schema,
set_task_instance_state_form,
task_instance_batch_form,
task_instance_collection_schema,
Expand Down Expand Up @@ -550,11 +550,11 @@ def post_set_task_instances_state(*, dag_id: str, session: Session = NEW_SESSION
return task_instance_reference_collection_schema.dump(TaskInstanceReferenceCollection(task_instances=tis))


def set_mapped_task_instance_notes(
def set_mapped_task_instance_note(
*, dag_id: str, dag_run_id: str, task_id: str, map_index: int
) -> APIResponse:
"""Set the note for a Mapped Task instance."""
return set_task_instance_notes(dag_id=dag_id, dag_run_id=dag_run_id, task_id=task_id, map_index=map_index)
return set_task_instance_note(dag_id=dag_id, dag_run_id=dag_run_id, task_id=task_id, map_index=map_index)


@security.requires_access(
Expand Down Expand Up @@ -629,13 +629,13 @@ def patch_mapped_task_instance(
],
)
@provide_session
def set_task_instance_notes(
def set_task_instance_note(
*, dag_id: str, dag_run_id: str, task_id: str, map_index: int = -1, session: Session = NEW_SESSION
) -> APIResponse:
"""Set the note for a Task instance. This supports both Mapped and non-Mapped Task instances."""
try:
post_body = set_task_instance_notes_form_schema.load(get_json_request_dict())
new_value_for_notes = post_body["notes"]
post_body = set_task_instance_note_form_schema.load(get_json_request_dict())
new_note = post_body["note"]
except ValidationError as err:
raise BadRequest(detail=str(err))

Expand Down Expand Up @@ -674,9 +674,9 @@ def set_task_instance_notes(

current_user_id = getattr(current_user, "id", None)
if ti.task_instance_note is None:
ti.notes = (new_value_for_notes, current_user_id)
ti.note = (new_note, current_user_id)
else:
ti.task_instance_note.content = new_value_for_notes
ti.task_instance_note.content = new_note
ti.task_instance_note.user_id = current_user_id
session.commit()
return task_instance_schema.dump((ti, sla_miss))
16 changes: 8 additions & 8 deletions airflow/api_connexion/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ paths:
*New in version 2.5.0*
x-openapi-router-controller: airflow.api_connexion.endpoints.task_instance_endpoint
operationId: set_task_instance_notes
operationId: set_task_instance_note
tags: [DAG]
requestBody:
description: Parameters of set Task Instance note.
Expand Down Expand Up @@ -638,7 +638,7 @@ paths:
*New in version 2.5.0*
x-openapi-router-controller: airflow.api_connexion.endpoints.task_instance_endpoint
operationId: set_mapped_task_instance_notes
operationId: set_mapped_task_instance_note
tags: [DAG]
requestBody:
description: Parameters of set Task Instance note.
Expand Down Expand Up @@ -935,7 +935,7 @@ paths:
*New in version 2.5.0*
x-openapi-router-controller: airflow.api_connexion.endpoints.dag_run_endpoint
operationId: set_dag_run_notes
operationId: set_dag_run_note
tags: [DAGRun]
requestBody:
description: Parameters of set DagRun note.
Expand Down Expand Up @@ -2808,7 +2808,7 @@ components:
The value of this field can be set only when creating the object. If you try to modify the
field of an existing object, the request fails with an BAD_REQUEST error.
notes:
note:
type: string
description: |
Contains manually entered notes by the user about the DagRun.
Expand Down Expand Up @@ -2884,7 +2884,7 @@ components:
SetDagRunNote:
type: object
properties:
notes:
note:
description: Custom notes left by users for this Dag Run.
type: string

Expand Down Expand Up @@ -3249,7 +3249,7 @@ components:
triggerer_job:
$ref: '#/components/schemas/Job'
nullable: true
notes:
note:
type: string
description: |
Contains manually entered notes by the user about the TaskInstance.
Expand Down Expand Up @@ -4174,9 +4174,9 @@ components:
SetTaskInstanceNote:
type: object
required:
- notes
- note
properties:
notes:
note:
description: The custom note to set for this Task Instance.
type: string

Expand Down
4 changes: 2 additions & 2 deletions airflow/api_connexion/schemas/dag_run_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Meta:
data_interval_end = auto_field(dump_only=True)
last_scheduling_decision = auto_field(dump_only=True)
run_type = auto_field(dump_only=True)
notes = auto_field(dump_only=True)
note = auto_field(dump_only=True)

@pre_load
def autogenerate(self, data, **kwargs):
Expand Down Expand Up @@ -167,7 +167,7 @@ class Meta:
class SetDagRunNoteFormSchema(Schema):
"""Schema for handling the request of clearing a DAG run."""

notes = fields.String(allow_none=True, validate=validate.Length(max=1000))
note = fields.String(allow_none=True, validate=validate.Length(max=1000))


dagrun_schema = DAGRunSchema()
Expand Down
6 changes: 3 additions & 3 deletions airflow/api_connexion/schemas/task_instance_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Meta:
queued_dttm = auto_field(data_key="queued_when")
pid = auto_field()
executor_config = auto_field()
notes = auto_field()
note = auto_field()
sla_miss = fields.Nested(SlaMissSchema, dump_default=None)
rendered_fields = JsonObjectField(dump_default={})
trigger = fields.Nested(TriggerSchema)
Expand Down Expand Up @@ -200,7 +200,7 @@ class SetTaskInstanceNoteFormSchema(Schema):

# Note: We can't add map_index to the url as subpaths can't start with dashes.
map_index = fields.Int(allow_none=False)
notes = fields.String(allow_none=True, validate=validate.Length(max=1000))
note = fields.String(allow_none=True, validate=validate.Length(max=1000))


task_instance_schema = TaskInstanceSchema()
Expand All @@ -211,4 +211,4 @@ class SetTaskInstanceNoteFormSchema(Schema):
set_single_task_instance_state_form = SetSingleTaskInstanceStateFormSchema()
task_instance_reference_schema = TaskInstanceReferenceSchema()
task_instance_reference_collection_schema = TaskInstanceReferenceCollectionSchema()
set_task_instance_notes_form_schema = SetTaskInstanceNoteFormSchema()
set_task_instance_note_form_schema = SetTaskInstanceNoteFormSchema()
2 changes: 1 addition & 1 deletion airflow/models/dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class DagRun(Base, LoggingMixin):
viewonly=True,
)
dag_run_note = relationship("DagRunNote", back_populates="dag_run", uselist=False)
notes = association_proxy("dag_run_note", "content", creator=_creator_note)
note = association_proxy("dag_run_note", "content", creator=_creator_note)

DEFAULT_DAGRUNS_TO_EXAMINE = airflow_conf.getint(
"scheduler",
Expand Down
2 changes: 1 addition & 1 deletion airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class TaskInstance(Base, LoggingMixin):
rendered_task_instance_fields = relationship("RenderedTaskInstanceFields", lazy="noload", uselist=False)
execution_date = association_proxy("dag_run", "execution_date")
task_instance_note = relationship("TaskInstanceNote", back_populates="task_instance", uselist=False)
notes = association_proxy("task_instance_note", "content", creator=_creator_note)
note = association_proxy("task_instance_note", "content", creator=_creator_note)
task: Operator # Not always set...

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions airflow/www/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class DagRunEditForm(DynamicForm):
widget=AirflowDateTimePickerROWidget(),
)
conf = TextAreaField(lazy_gettext("Conf"), widget=BS3TextAreaROWidget())
notes = TextAreaField(lazy_gettext("User Note"), widget=BS3TextAreaFieldWidget())
note = TextAreaField(lazy_gettext("User Note"), widget=BS3TextAreaFieldWidget())

def populate_obj(self, item):
"""Populates the attributes of the passed obj with data from the form's fields."""
Expand Down Expand Up @@ -173,7 +173,7 @@ class TaskInstanceEditForm(DynamicForm):
widget=AirflowDateTimePickerROWidget(),
validators=[InputRequired()],
)
notes = TextAreaField(lazy_gettext("User Note"), widget=BS3TextAreaFieldWidget())
note = TextAreaField(lazy_gettext("User Note"), widget=BS3TextAreaFieldWidget())


class ConnectionForm(DynamicForm):
Expand Down
8 changes: 4 additions & 4 deletions airflow/www/static/js/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import useDatasets from './useDatasets';
import useDataset from './useDataset';
import useDatasetDependencies from './useDatasetDependencies';
import useDatasetEvents from './useDatasetEvents';
import useSetDagRunNotes from './useSetDagRunNotes';
import useSetTaskInstanceNotes from './useSetTaskInstanceNotes';
import useSetDagRunNote from './useSetDagRunNote';
import useSetTaskInstanceNote from './useSetTaskInstanceNote';
import useUpstreamDatasetEvents from './useUpstreamDatasetEvents';
import useTaskInstance from './useTaskInstance';

Expand All @@ -64,8 +64,8 @@ export {
useMarkSuccessTask,
useQueueRun,
useRunTask,
useSetDagRunNotes,
useSetTaskInstanceNotes,
useSetDagRunNote,
useSetTaskInstanceNote,
useTaskInstance,
useUpstreamDatasetEvents,
};
2 changes: 1 addition & 1 deletion airflow/www/static/js/api/useGridData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const commonDagRunParams = {
externalTrigger: false,
conf: null,
confIsJson: false,
notes: '',
note: '',
};

describe('Test areActiveRuns()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ import useErrorToast from 'src/utils/useErrorToast';
import { emptyGridData } from './useGridData';
import type { GridData } from './useGridData';

const setDagRunNotesURI = getMetaValue('set_dag_run_notes');
const setDagRunNoteURI = getMetaValue('set_dag_run_note');

interface Props {
dagId: string;
runId: string;
}

export default function useSetDagRunNotes({
export default function useSetDagRunNote({
dagId, runId,
}: Props) {
const queryClient = useQueryClient();
const errorToast = useErrorToast();
const setDagRunNotes = setDagRunNotesURI.replace('_DAG_RUN_ID_', runId);
const setDagRunNote = setDagRunNoteURI.replace('_DAG_RUN_ID_', runId);

return useMutation(
['setDagRunNotes', dagId, runId],
(notes: string | null) => axios.patch<AxiosResponse, API.DAGRun>(setDagRunNotes, { notes }),
['setDagRunNote', dagId, runId],
(note: string | null) => axios.patch<AxiosResponse, API.DAGRun>(setDagRunNote, { note }),
{
onSuccess: async (data) => {
const notes = data.notes ?? null;
const note = data.note ?? null;

const updateGridData = (oldGridData: GridData | undefined) => (
!oldGridData
? emptyGridData
: {
...oldGridData,
dagRuns: oldGridData.dagRuns.map((dr) => (
dr.runId === runId ? { ...dr, notes } : dr)),
dr.runId === runId ? { ...dr, note } : dr)),
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import useErrorToast from 'src/utils/useErrorToast';

import type { API } from 'src/types';

const setTaskInstancesNotesURI = getMetaValue('set_task_instance_notes');
const setMappedTaskInstancesNotesURI = getMetaValue('set_mapped_task_instance_notes');
const setTaskInstancesNoteURI = getMetaValue('set_task_instance_note');
const setMappedTaskInstancesNoteURI = getMetaValue('set_mapped_task_instance_note');

interface Props {
dagId: string;
Expand All @@ -35,25 +35,25 @@ interface Props {
mapIndex?: number;
}

export default function useSetTaskInstanceNotes({
export default function useSetTaskInstanceNote({
dagId, runId, taskId, mapIndex = -1,
}: Props) {
const queryClient = useQueryClient();
const errorToast = useErrorToast();
// Note: Werkzeug does not like the META URL on dag.html with an integer. It can not put
// _MAP_INDEX_ there as it interprets that as the integer. Hence, we pass 0 as the integer.
// To avoid we replace other stuff, we add the surrounding strings to the replacement query.
const url = (mapIndex >= 0 ? setMappedTaskInstancesNotesURI : setTaskInstancesNotesURI)
const url = (mapIndex >= 0 ? setMappedTaskInstancesNoteURI : setTaskInstancesNoteURI)
.replace('_DAG_RUN_ID_', runId)
.replace('_TASK_ID_/0/setNote', `_TASK_ID_/${mapIndex}/setNote`)
.replace('_TASK_ID_', taskId);

return useMutation(
['setTaskInstanceNotes', dagId, runId, taskId, mapIndex],
(notes: string | null) => axios.patch<AxiosResponse, API.TaskInstance>(url, { notes }),
(note: string | null) => axios.patch<AxiosResponse, API.TaskInstance>(url, { note }),
{
onSuccess: async (data) => {
const notes = data.notes ?? null;
const note = data.note ?? null;

const updateMappedInstancesResult = (oldMappedInstances?: API.TaskInstanceCollection) => {
if (!oldMappedInstances) {
Expand All @@ -67,7 +67,7 @@ export default function useSetTaskInstanceNotes({
...oldMappedInstances,
taskInstances: oldMappedInstances.taskInstances?.map((ti) => (
ti.dagRunId === runId && ti.taskId === taskId && ti.mapIndex === mapIndex
? { ...ti, notes }
? { ...ti, note }
: ti
)),
};
Expand All @@ -85,7 +85,7 @@ export default function useSetTaskInstanceNotes({
) {
return {
...oldTaskInstance,
notes,
note,
};
}
return oldTaskInstance;
Expand Down
6 changes: 3 additions & 3 deletions airflow/www/static/js/dag/InstanceTooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const instance = {
state: 'success' as TaskState,
runId: 'run',
taskId: 'task',
notes: '',
note: '',
};

describe('Test Task InstanceTooltip', () => {
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Test Task InstanceTooltip', () => {
state: 'success',
startDate: '',
endDate: '',
notes: '',
note: '',
},
],
},
Expand All @@ -104,7 +104,7 @@ describe('Test Task InstanceTooltip', () => {
const { getByText } = render(
<InstanceTooltip
group={{ id: 'task', label: 'task', instances: [] }}
instance={{ ...instance, notes: 'note' }}
instance={{ ...instance, note: 'note' }}
/>,
{ wrapper: Wrapper },
);
Expand Down
Loading

0 comments on commit 3b032e5

Please sign in to comment.