Skip to content

Commit

Permalink
remove 'temporary arg'
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Nov 14, 2024
1 parent d81d145 commit 82626db
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 58 deletions.
30 changes: 0 additions & 30 deletions osf/management/commands/recatalog_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ def _recatalog_all(queryset, chunk_size):
recatalog(queryset, start_id=0, chunk_count=int(9e9), chunk_size=chunk_size)


def _recatalog_datacite_custom_types(chunk_size):
logger.info('recataloguing items with datacite custom type...')
# all preprints
_recatalog_all(Preprint.objects, chunk_size)
# objects with custom resource_type_general
for _model in {Registration, Node, OsfStorageFile}:
_queryset = (
_model.objects
.exclude(guids__metadata_record__isnull=True)
.exclude(guids__metadata_record__resource_type_general='')
)
_recatalog_all(_queryset, chunk_size)
logger.info('done recataloguing items with datacite custom type!')


class Command(BaseCommand):
def add_arguments(self, parser):
type_group = parser.add_mutually_exclusive_group(required=True)
Expand Down Expand Up @@ -103,14 +88,6 @@ def add_arguments(self, parser):
action='store_true',
help='recatalog metadata for users',
)
type_group.add_argument(
'--datacite-custom-types',
action='store_true',
help='''recatalog metadata for items with a specific datacite type,
including all preprints and items with custom resource_type_general
(may be slow for lack of database indexes)
''',
)

provider_group = parser.add_mutually_exclusive_group()
provider_group.add_argument(
Expand Down Expand Up @@ -161,15 +138,8 @@ def handle(self, *args, **options):
start_id = options['start_id']
chunk_size = options['chunk_size']
chunk_count = options['chunk_count']
datacite_custom_types = options['datacite_custom_types']
also_decatalog = options['also_decatalog']

if datacite_custom_types: # temporary arg for datacite 4.5 migration
assert not start_id, 'oh no, cannot resume with `--datacite-custom-types`'
assert not provider_ids, 'oh no, cannot filter providers with `--datacite-custom-types`'
_recatalog_datacite_custom_types(chunk_size)
return # end

if pls_all_types:
assert not start_id, 'choose a specific type to resume with --start-id'
provided_models = [Preprint, Registration, Node, OSFUser, OsfStorageFile]
Expand Down
28 changes: 0 additions & 28 deletions osf_tests/management_commands/test_recatalog_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import pytest
from unittest import mock
from operator import attrgetter
import random

from django.core.management import call_command

from osf.models.metadata import GuidMetadataRecord
from osf_tests.factories import (
PreprintProviderFactory,
PreprintFactory,
Expand Down Expand Up @@ -77,21 +75,6 @@ def users(self, preprints, registrations, projects):
for preprint in preprints
])))

@pytest.fixture
def items_with_custom_datacite_type(self, preprints, registrations, projects, files):
_nonpreprint_sample = [
random.choice(_items)
for _items in (registrations, projects, files)
]
for _item in _nonpreprint_sample:
_guid_record = GuidMetadataRecord.objects.for_guid(_item)
_guid_record.resource_type_general = 'BookChapter' # datacite resourceTypeGeneral value
_guid_record.save()
return {
*preprints, # every preprint has datacite type "Preprint"
*_nonpreprint_sample,
}

@pytest.fixture
def decatalog_items(self, registrations):
_user = UserFactory(allow_indexing=False)
Expand Down Expand Up @@ -119,7 +102,6 @@ def test_recatalog_metadata(
projects,
files,
users,
items_with_custom_datacite_type,
decatalog_items,
):
def _actual_osfids() -> set[str]:
Expand Down Expand Up @@ -206,16 +188,6 @@ def _actual_osfids() -> set[str]:

mock_update_share_task.reset_mock()

# datacite custom types
call_command(
'recatalog_metadata',
'--datacite-custom-types',
)
_expected_osfids = set(_iter_osfids(items_with_custom_datacite_type))
assert _expected_osfids == _actual_osfids()

mock_update_share_task.reset_mock()

# all types
_all_public_items = [*preprints, *registrations, *projects, *files, *users]
call_command(
Expand Down

0 comments on commit 82626db

Please sign in to comment.