You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by je...@apache.org on 2022/05/26 23:33:49 UTC
[airflow] 08/09: Prevent UI from crashing if grid task instances are null (#23939)
This is an automated email from the ASF dual-hosted git repository.
jedcunningham pushed a commit to branch v2-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit a88900c8a71966d2eb7b4577f114915aee761ad6
Author: Brent Bovenzi <br...@gmail.com>
AuthorDate: Thu May 26 18:20:14 2022 +0200
Prevent UI from crashing if grid task instances are null (#23939)
* UI fix for null task instances
* improve tests without global vars
* fix test data
(cherry picked from commit 9314a4ab8bf11e56125cbca6b012d61d1002ac32)
---
airflow/www/static/js/grid/renderTaskRows.jsx | 2 +-
airflow/www/static/js/grid/renderTaskRows.test.jsx | 140 +++++++++++++--------
2 files changed, 87 insertions(+), 55 deletions(-)
diff --git a/airflow/www/static/js/grid/renderTaskRows.jsx b/airflow/www/static/js/grid/renderTaskRows.jsx
index 4f3abb8594..b57ca59b40 100644
--- a/airflow/www/static/js/grid/renderTaskRows.jsx
+++ b/airflow/www/static/js/grid/renderTaskRows.jsx
@@ -53,7 +53,7 @@ const TaskInstances = ({
<Flex justifyContent="flex-end">
{dagRunIds.map((runId) => {
// Check if an instance exists for the run, or return an empty box
- const instance = task.instances.find((gi) => gi.runId === runId);
+ const instance = task.instances.find((gi) => gi && gi.runId === runId);
const isSelected = selectedRunId === runId;
return (
<Box
diff --git a/airflow/www/static/js/grid/renderTaskRows.test.jsx b/airflow/www/static/js/grid/renderTaskRows.test.jsx
index 2a8c276adb..7b1596512a 100644
--- a/airflow/www/static/js/grid/renderTaskRows.test.jsx
+++ b/airflow/www/static/js/grid/renderTaskRows.test.jsx
@@ -25,33 +25,16 @@ import { render } from '@testing-library/react';
import renderTaskRows from './renderTaskRows';
import { TableWrapper } from './utils/testUtils';
-const mockGroup = {
- id: null,
- label: null,
- children: [
- {
- extraLinks: [],
- id: 'group_1',
- label: 'group_1',
- instances: [
- {
- dagId: 'dagId',
- duration: 0,
- endDate: '2021-10-26T15:42:03.391939+00:00',
- executionDate: '2021-10-25T15:41:09.726436+00:00',
- operator: 'DummyOperator',
- runId: 'run1',
- startDate: '2021-10-26T15:42:03.391917+00:00',
- state: 'success',
- taskId: 'group_1',
- tryNumber: 1,
- },
- ],
+describe('Test renderTaskRows', () => {
+ test('Renders name and task instance', () => {
+ const task = {
+ id: null,
+ label: null,
children: [
{
- id: 'group_1.task_1',
- label: 'group_1.task_1',
extraLinks: [],
+ id: 'group_1',
+ label: 'group_1',
instances: [
{
dagId: 'dagId',
@@ -62,44 +45,60 @@ const mockGroup = {
runId: 'run1',
startDate: '2021-10-26T15:42:03.391917+00:00',
state: 'success',
- taskId: 'group_1.task_1',
+ taskId: 'group_1',
tryNumber: 1,
},
],
+ children: [
+ {
+ id: 'group_1.task_1',
+ label: 'group_1.task_1',
+ extraLinks: [],
+ instances: [
+ {
+ dagId: 'dagId',
+ duration: 0,
+ endDate: '2021-10-26T15:42:03.391939+00:00',
+ executionDate: '2021-10-25T15:41:09.726436+00:00',
+ operator: 'DummyOperator',
+ runId: 'run1',
+ startDate: '2021-10-26T15:42:03.391917+00:00',
+ state: 'success',
+ taskId: 'group_1.task_1',
+ tryNumber: 1,
+ },
+ ],
+ },
+ ],
},
],
- },
- ],
- instances: [],
-};
+ instances: [],
+ };
+
+ const { queryByTestId, getByText } = render(
+ <>{renderTaskRows({ task, dagRunIds: ['run1'] })}</>,
+ { wrapper: TableWrapper },
+ );
+
+ expect(getByText('group_1')).toBeInTheDocument();
+ expect(queryByTestId('task-instance')).toBeDefined();
+ expect(queryByTestId('blank-task')).toBeNull();
+ });
-describe('Test renderTaskRows', () => {
test('Still renders names if there are no instances', () => {
- global.gridData = {
- groups: {
- id: null,
- label: null,
- children: [
- {
- extraLinks: [],
- id: 'group_1',
- label: 'group_1',
- instances: [],
- children: [
- {
- id: 'group_1.task_1',
- label: 'group_1.task_1',
- extraLinks: [],
- instances: [],
- },
- ],
- },
- ],
- instances: [],
- },
- dagRuns: [],
+ const task = {
+ id: null,
+ label: null,
+ children: [
+ {
+ extraLinks: [],
+ id: 'group_1',
+ label: 'group_1',
+ instances: [],
+ },
+ ],
+ instances: [],
};
- const task = mockGroup;
const { queryByTestId, getByText } = render(
<>{renderTaskRows({ task, dagRunIds: [] })}</>,
@@ -109,4 +108,37 @@ describe('Test renderTaskRows', () => {
expect(getByText('group_1')).toBeInTheDocument();
expect(queryByTestId('task-instance')).toBeNull();
});
+
+ test('Still renders correctly if task instance is null', () => {
+ const task = {
+ id: null,
+ label: null,
+ children: [
+ {
+ extraLinks: [],
+ id: 'group_1',
+ label: 'group_1',
+ instances: [null],
+ children: [
+ {
+ id: 'group_1.task_1',
+ label: 'group_1.task_1',
+ extraLinks: [],
+ instances: [null],
+ },
+ ],
+ },
+ ],
+ instances: [null],
+ };
+
+ const { queryByTestId, getByText } = render(
+ <>{renderTaskRows({ task, dagRunIds: ['run1'] })}</>,
+ { wrapper: TableWrapper },
+ );
+
+ expect(getByText('group_1')).toBeInTheDocument();
+ expect(queryByTestId('task-instance')).toBeNull();
+ expect(queryByTestId('blank-task')).toBeInTheDocument();
+ });
});