Skip to content

Commit

Permalink
make Run migration ids unique by relative path instead of absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Grubenmann committed Oct 1, 2020
1 parent dae968c commit a100c54
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions renku/core/management/migrations/m_0005__2_cwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os
import uuid
from functools import cmp_to_key
from hashlib import sha256
from hashlib import sha1
from pathlib import Path

from cwlgen import CommandLineTool, parse_cwl
Expand Down Expand Up @@ -124,11 +124,12 @@ def _migrate_single_step(client, cmd_line_tool, path, commit=None, parent_commit
outputs = list(cmd_line_tool.outputs)

# NOTE: Make run ids deterministic to prevent duplication.
rel_path = Path(path).relative_to(client.path)
if parent_commit:
label = f"{path}@{parent_commit.hexsha}"
label = f"{rel_path}@{parent_commit.hexsha}"
else:
label = f"{path}@{commit.hexsha}"
identifier = sha256(label.encode("utf-8")).hexdigest()
label = f"{rel_path}@{commit.hexsha}"
identifier = sha1(label.encode("utf-8")).hexdigest()

base_id = Run.generate_id(client, identifier=identifier)
run._id = base_id
Expand Down Expand Up @@ -305,9 +306,9 @@ def _migrate_composite_step(client, workflow, path, commit=None):
if not commit:
commit = client.find_previous_commit(path)
run = Run(client=client, path=path, commit=commit)

label = f"{path}@{commit.hexsha}"
identifier = sha256(label.encode("utf-8")).hexdigest()
rel_path = Path(path).relative_to(client.path)
label = f"{rel_path}@{commit.hexsha}"
identifier = sha1(label.encode("utf-8")).hexdigest()
run._id = Run.generate_id(client, identifier=identifier)

name = "{0}_migrated.yaml".format(uuid.uuid4().hex)
Expand Down

0 comments on commit a100c54

Please sign in to comment.