Skip to content

Commit 2766472

Browse files
authored
Batch Edit: Match/Create record for independent relationship if all visible fields are null. (#7087)
* (bug): Regenerate predicates if no fields in predicates found * Lint code with ESLint and Prettier Triggered by c883cfc on branch refs/heads/issue-6569
1 parent 7aa0b43 commit 2766472

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

specifyweb/frontend/js_src/lib/components/Attachments/__tests__/UploadAttachment.test.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1+
import { fireEvent, waitFor } from '@testing-library/react';
12
import React from 'react';
2-
import { mount } from '../../../tests/reactUtils';
3-
import { UploadAttachment } from '../Plugin';
3+
44
import { clearIdStore } from '../../../hooks/useId';
5-
import { LoadingContext } from '../../Core/Contexts';
6-
import { f } from '../../../utils/functools';
7-
import { fireEvent, waitFor } from '@testing-library/react';
8-
import { overrideAttachmentSettings } from '../attachments';
9-
import attachmentSettings from '../../../tests/ajax/static/context/attachment_settings.json';
105
import { overrideAjax } from '../../../tests/ajax';
11-
import * as Attachments from '../attachments';
6+
import attachmentSettings from '../../../tests/ajax/static/context/attachment_settings.json';
127
import { requireContext } from '../../../tests/helpers';
13-
import { deserializeResource } from '../../DataModel/serializers';
14-
import { testAttachment } from './utils';
8+
import { mount } from '../../../tests/reactUtils';
9+
import { f } from '../../../utils/functools';
10+
import { LoadingContext } from '../../Core/Contexts';
1511
import { SpecifyResource } from '../../DataModel/legacyTypes';
12+
import { deserializeResource } from '../../DataModel/serializers';
1613
import { Attachment } from '../../DataModel/types';
14+
import { overrideAttachmentSettings } from '../attachments';
15+
import * as Attachments from '../attachments';
16+
import { UploadAttachment } from '../Plugin';
17+
import { testAttachment } from './utils';
1718

1819
requireContext();
1920

2021
async function uploadFileMock() {
21-
return deserializeResource(testAttachment) as SpecifyResource<Attachment>;
22+
return deserializeResource(testAttachment) ;
2223
}
2324

2425
beforeEach(() => {
@@ -57,7 +58,7 @@ describe('UploadAttachment', () => {
5758
fireEvent.change(input, { target: { files: [testFile] } });
5859

5960
await waitFor(() => {
60-
expect(handleUploaded).toBeCalled();
61+
expect(handleUploaded).toHaveBeenCalled();
6162
});
6263
});
6364
});

specifyweb/workbench/upload/upload_table.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,23 @@ def _handle_row(self, skip_match: bool, allow_null: bool) -> UploadResult:
603603
# nothing to upload
604604
return UploadResult(NullRecord(info), to_one_results, {})
605605
if not skip_match:
606+
assert not is_edit_table, "Trying to match update table!"
607+
608+
if not filter_predicate.filters and self.current_id is not None:
609+
# Technically, we'll get always the empty predicate back if self.current_id is None
610+
# So, we can skip the check for "self.current_id is not None:". But, it
611+
# is an optimization (a micro-one)
612+
filter_predicate = self.get_django_predicates(
613+
should_defer_match=self._should_defer_match,
614+
# to_one_results should be completely empty (or all nulls)
615+
# Having it here is an optimization.
616+
to_one_override=to_one_results,
617+
consider_dependents=False,
618+
# Don't necessarily reduce the empty fields now.
619+
is_origin=False,
620+
origin_is_editable=False
621+
)
622+
606623
match = self._match(filter_predicate, info)
607624
if match:
608625
return UploadResult(match, to_one_results, {})

0 commit comments

Comments
 (0)