diff --git a/bookmarks/services/importer.py b/bookmarks/services/importer.py index 2259ef8..eb59367 100644 --- a/bookmarks/services/importer.py +++ b/bookmarks/services/importer.py @@ -173,6 +173,7 @@ def _import_batch(netscape_bookmarks: List[NetscapeBookmark], user: User, tag_ca shortened_bookmark_tag_str = str(netscape_bookmark)[:100] + '...' logging.warning( f'Failed to assign tags to the bookmark: {shortened_bookmark_tag_str}. Could not find bookmark by URL.') + continue # Get tag models by string, schedule inserts for bookmark -> tag associations tag_names = parse_tag_string(netscape_bookmark.tag_string) diff --git a/bookmarks/tests/test_importer.py b/bookmarks/tests/test_importer.py index d814d1f..29cb8e0 100644 --- a/bookmarks/tests/test_importer.py +++ b/bookmarks/tests/test_importer.py @@ -111,6 +111,19 @@ class ImporterTestCase(TestCase, BookmarkFactoryMixin, ImportTestMixin): self.assertEqual(len(bookmarks), 1) self.assertBookmarksImported(html_tags[1:1]) + def test_import_invalid_bookmark_does_not_associate_tags(self): + html_tags = [ + # No URL + BookmarkHtmlTag(tags='tag1, tag2, tag3'), + ] + import_html = self.render_html(tags=html_tags) + # Sqlite silently ignores relationships that have a non-persisted bookmark, + # thus testing if the bulk create receives no relationships + BookmarkToTagRelationShip = Bookmark.tags.through + with patch.object(BookmarkToTagRelationShip.objects, 'bulk_create') as mock_bulk_create: + import_netscape_html(import_html, self.get_or_create_test_user()) + mock_bulk_create.assert_called_once_with([], ignore_conflicts=True) + def test_import_tags(self): html_tags = [ BookmarkHtmlTag(href='https://example.com', tags='tag1'),