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(service): dataset import error #3670

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover
.hypothesis

# Translations
*.mo
Expand Down
4 changes: 2 additions & 2 deletions renku/core/dataset/providers/zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class ZenodoDatasetSchema(ProviderDatasetSchema):
"""Schema for Zenodo datasets."""

@pre_load
def fix_data(self, data, **kwargs):
def fix_data(self, data, **_):
"""Fix data that is received from Zenodo."""
# Fix context
context = data.get("@context")
Expand Down Expand Up @@ -236,7 +236,7 @@ def fix_data(self, data, **kwargs):
class ZenodoFileSerializer:
"""Zenodo record file."""

def __init__(self, *, id=None, checksum=None, links=None, key=None, size=None, **kwargs):
def __init__(self, *, id=None, checksum=None, links=None, key=None, size=None, **_):
self.id = id
self.checksum = checksum
self.links = links
Expand Down
2 changes: 1 addition & 1 deletion renku/ui/service/controllers/datasets_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def renku_op(self):
"""Renku operation for the controller."""
job = self.cache.make_job(
self.user,
# NOTE: To support operation to be execute on remote project, this behaviour should be updated.
# NOTE: To support operation to be executed on remote project, this behaviour should be updated.
project=self.ctx["project_id"],
job_data={"renku_op": "dataset_import", "client_extras": self.ctx.get("client_extras")},
)
Expand Down
10 changes: 5 additions & 5 deletions renku/ui/service/jobs/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def dataset_import(
user_job_id,
project_id,
dataset_uri,
name=None,
slug=None,
extract=False,
tag=None,
timeout=None,
Expand All @@ -63,7 +63,7 @@ def dataset_import(
command = import_dataset_command().with_commit_message(commit_message)
command.with_communicator(communicator).build().execute(
uri=dataset_uri,
name=name,
slug=slug,
extract=extract,
tag=tag,
yes=True,
Expand Down Expand Up @@ -98,7 +98,7 @@ def _is_safe_to_pass_gitlab_token(project_git_url, dataset_uri):


@requires_cache
def dataset_add_remote_file(cache, user, user_job_id, project_id, create_dataset, commit_message, name, url):
def dataset_add_remote_file(cache, user, user_job_id, project_id, create_dataset, commit_message, slug, url):
"""Add a remote file to a specified dataset."""
user = cache.ensure_user(user)
worker_log.debug(f"executing dataset add remote file job for {user.user_id}:{user.fullname}")
Expand All @@ -113,9 +113,9 @@ def dataset_add_remote_file(cache, user, user_job_id, project_id, create_dataset
with renku_project_context(project.abs_path):
urls = url if isinstance(url, list) else [url]

worker_log.debug(f"adding files {urls} to dataset {name}")
worker_log.debug(f"adding files {urls} to dataset {slug}")
command = add_to_dataset_command().with_commit_message(commit_message).build()
result = command.execute(dataset_slug=name, urls=urls, create=create_dataset)
result = command.execute(dataset_slug=slug, urls=urls, create=create_dataset)
if result.error:
raise result.error

Expand Down
24 changes: 20 additions & 4 deletions tests/service/jobs/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def test_dataset_url_import_job(url, svc_client_with_repo):
@pytest.mark.service
@retry_failed
@pytest.mark.vcr
def test_dataset_import_job(doi, svc_client_with_repo):
"""Test dataset import via doi."""
def test_dataset_import_job_with_slug(doi, svc_client_with_repo):
"""Test dataset import via doi and give it a slug."""
svc_client, headers, project_id, url_components = svc_client_with_repo

user_id = encode_b64(secure_filename("9ab2fc80-3a5c-426d-ae78-56de01d214df"))
Expand Down Expand Up @@ -118,7 +118,14 @@ def test_dataset_import_job(doi, svc_client_with_repo):
job_id = response.json["result"]["job_id"]

commit_message = "service: import remote dataset"
dataset_import(user, job_id, project_id, doi, commit_message=commit_message)
dataset_import(
user=user,
user_job_id=job_id,
project_id=project_id,
dataset_uri=doi,
slug="dataset-slug",
commit_message=commit_message,
)

new_commit = Repository(dest).head.commit
assert old_commit.hexsha != new_commit.hexsha
Expand Down Expand Up @@ -279,7 +286,16 @@ def test_dataset_add_remote_file(url, svc_client_with_repo):
job_id = response.json["result"]["files"][0]["job_id"]
commit_message = "service: dataset add remote file"

dataset_add_remote_file(user, job_id, project_id, True, commit_message, payload["slug"], url)
# user, user_job_id, project_id, create_dataset, commit_message, slug, url
dataset_add_remote_file(
user=user,
user_job_id=job_id,
project_id=project_id,
create_dataset=True,
commit_message=commit_message,
slug=payload["slug"],
url=url,
)

new_commit = Repository(dest).head.commit

Expand Down