Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto refresh for graph view #26926

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions airflow/www/static/js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,10 @@ function handleRefresh() {
// only refresh if the data has changed
if (prevTis !== tis) {
// eslint-disable-next-line no-global-assign
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of this line now

taskInstances = JSON.parse(tis);
updateNodesStates(taskInstances);
updateNodesStates(tis);

// Only redraw the graph if labels have changed
const haveLabelsChanged = updateNodeLabels(nodes, taskInstances);
const haveLabelsChanged = updateNodeLabels(nodes, tis);
if (haveLabelsChanged) draw();

// end refresh if all states are final
Expand Down
217 changes: 217 additions & 0 deletions tests/www/views/test_views_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,220 @@ def test_graph_view_doesnt_fail_on_recursion_error(app, dag_maker, admin_client)
url = f'/dags/{dag.dag_id}/graph'
resp = admin_client.get(url, follow_redirects=True)
assert resp.status_code == 200


def test_task_instances(app, dag_maker, admin_client):
"""Test task_instances view."""
resp = admin_client.get(
f'/object/task_instances?dag_id=example_bash_operator&execution_date={DEFAULT_DATE}',
follow_redirects=True,
)
assert resp.status_code == 200
payload = resp.json
for v in payload.values():
assert v.pop('updated_at')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to mock the server_default, for updated_at so I can assert the entire response ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit to do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @uranusjr, much cleaner this way. I naively froze time on the test, which had no effect since fixture init happens before 🤦‍♂️

assert payload == {
'also_run_this': {
'dag_id': 'example_bash_operator',
'duration': None,
'end_date': None,
'executor_config': {},
'external_executor_id': None,
'hostname': '',
'job_id': None,
'map_index': -1,
'max_tries': 0,
'next_kwargs': None,
'next_method': None,
'operator': 'BashOperator',
'pid': None,
'pool': 'default_pool',
'pool_slots': 1,
'priority_weight': 2,
'queue': 'default',
'queued_by_job_id': None,
'queued_dttm': None,
'run_id': 'TEST_DAGRUN',
'start_date': None,
'state': None,
'task_id': 'also_run_this',
'trigger_id': None,
'trigger_timeout': None,
'try_number': 1,
'unixname': 'root',
},
'run_after_loop': {
'dag_id': 'example_bash_operator',
'duration': None,
'end_date': None,
'executor_config': {},
'external_executor_id': None,
'hostname': '',
'job_id': None,
'map_index': -1,
'max_tries': 0,
'next_kwargs': None,
'next_method': None,
'operator': 'BashOperator',
'pid': None,
'pool': 'default_pool',
'pool_slots': 1,
'priority_weight': 2,
'queue': 'default',
'queued_by_job_id': None,
'queued_dttm': None,
'run_id': 'TEST_DAGRUN',
'start_date': None,
'state': None,
'task_id': 'run_after_loop',
'trigger_id': None,
'trigger_timeout': None,
'try_number': 1,
'unixname': 'root',
},
'run_this_last': {
'dag_id': 'example_bash_operator',
'duration': None,
'end_date': None,
'executor_config': {},
'external_executor_id': None,
'hostname': '',
'job_id': None,
'map_index': -1,
'max_tries': 0,
'next_kwargs': None,
'next_method': None,
'operator': 'EmptyOperator',
'pid': None,
'pool': 'default_pool',
'pool_slots': 1,
'priority_weight': 1,
'queue': 'default',
'queued_by_job_id': None,
'queued_dttm': None,
'run_id': 'TEST_DAGRUN',
'start_date': None,
'state': None,
'task_id': 'run_this_last',
'trigger_id': None,
'trigger_timeout': None,
'try_number': 1,
'unixname': 'root',
},
'runme_0': {
'dag_id': 'example_bash_operator',
'duration': None,
'end_date': None,
'executor_config': {},
'external_executor_id': None,
'hostname': '',
'job_id': None,
'map_index': -1,
'max_tries': 0,
'next_kwargs': None,
'next_method': None,
'operator': 'BashOperator',
'pid': None,
'pool': 'default_pool',
'pool_slots': 1,
'priority_weight': 3,
'queue': 'default',
'queued_by_job_id': None,
'queued_dttm': None,
'run_id': 'TEST_DAGRUN',
'start_date': None,
'state': None,
'task_id': 'runme_0',
'trigger_id': None,
'trigger_timeout': None,
'try_number': 1,
'unixname': 'root',
},
'runme_1': {
'dag_id': 'example_bash_operator',
'duration': None,
'end_date': None,
'executor_config': {},
'external_executor_id': None,
'hostname': '',
'job_id': None,
'map_index': -1,
'max_tries': 0,
'next_kwargs': None,
'next_method': None,
'operator': 'BashOperator',
'pid': None,
'pool': 'default_pool',
'pool_slots': 1,
'priority_weight': 3,
'queue': 'default',
'queued_by_job_id': None,
'queued_dttm': None,
'run_id': 'TEST_DAGRUN',
'start_date': None,
'state': None,
'task_id': 'runme_1',
'trigger_id': None,
'trigger_timeout': None,
'try_number': 1,
'unixname': 'root',
},
'runme_2': {
'dag_id': 'example_bash_operator',
'duration': None,
'end_date': None,
'executor_config': {},
'external_executor_id': None,
'hostname': '',
'job_id': None,
'map_index': -1,
'max_tries': 0,
'next_kwargs': None,
'next_method': None,
'operator': 'BashOperator',
'pid': None,
'pool': 'default_pool',
'pool_slots': 1,
'priority_weight': 3,
'queue': 'default',
'queued_by_job_id': None,
'queued_dttm': None,
'run_id': 'TEST_DAGRUN',
'start_date': None,
'state': None,
'task_id': 'runme_2',
'trigger_id': None,
'trigger_timeout': None,
'try_number': 1,
'unixname': 'root',
},
'this_will_skip': {
'dag_id': 'example_bash_operator',
'duration': None,
'end_date': None,
'executor_config': {},
'external_executor_id': None,
'hostname': '',
'job_id': None,
'map_index': -1,
'max_tries': 0,
'next_kwargs': None,
'next_method': None,
'operator': 'BashOperator',
'pid': None,
'pool': 'default_pool',
'pool_slots': 1,
'priority_weight': 2,
'queue': 'default',
'queued_by_job_id': None,
'queued_dttm': None,
'run_id': 'TEST_DAGRUN',
'start_date': None,
'state': None,
'task_id': 'this_will_skip',
'trigger_id': None,
'trigger_timeout': None,
'try_number': 1,
'unixname': 'root',
},
}