Skip to content

Commit

Permalink
fix: make doctor fix for workflow ids also update oid and derived_from (
Browse files Browse the repository at this point in the history
#3723)

* fix(cli): fix the doctor fix for plan ids to reassign oid's

* allow overriding renku lock path

* also fix derived from
  • Loading branch information
Panaetius committed Apr 8, 2024
1 parent ec72507 commit 050ed61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
18 changes: 16 additions & 2 deletions renku/command/checks/workflow.py
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Checks needed to determine integrity of workflows."""

from datetime import timedelta
from typing import List, Optional, Tuple, cast

Expand Down Expand Up @@ -145,14 +146,17 @@ def check_plan_id(fix, plan_gateway: IPlanGateway, **_) -> Tuple[bool, bool, Opt
plans: List[AbstractPlan] = plan_gateway.get_all_plans()

to_be_processed = []
to_be_processed_derived = []
for plan in plans:
if isinstance(plan.id, str) and plan.id.startswith("/plans//plans"):
to_be_processed.append(plan)
if isinstance(plan.derived_from, str) and plan.derived_from.startswith("/plans//plans"):
to_be_processed_derived.append(plan)

if not to_be_processed:
if not to_be_processed and not to_be_processed_derived:
return True, False, None
if not fix:
ids = [plan.id for plan in to_be_processed]
ids = [plan.id for plan in to_be_processed + to_be_processed_derived]
message = (
WARNING
+ "The following workflows have incorrect IDs (use 'renku doctor --fix' to fix them):\n\t"
Expand All @@ -163,7 +167,17 @@ def check_plan_id(fix, plan_gateway: IPlanGateway, **_) -> Tuple[bool, bool, Opt
for plan in to_be_processed:
plan.unfreeze()
plan.id = plan.id.replace("//plans/", "/")
plan.reassign_oid()
plan._p_changed = True
plan.freeze()

for plan in to_be_processed_derived:
if plan.derived_from is not None:
plan.unfreeze()
plan.derived_from = plan.derived_from.replace("//plans/", "/")
plan._p_changed = True
plan.freeze()

project_context.database.commit()
communication.info("Workflow IDs were fixed")

Expand Down
14 changes: 13 additions & 1 deletion renku/core/config.py
Expand Up @@ -18,6 +18,7 @@
import configparser
import os
from io import StringIO
from pathlib import Path

from renku.core.constant import DATA_DIR_CONFIG_KEY
from renku.domain_model.enums import ConfigFilter
Expand All @@ -28,13 +29,21 @@ def global_config_read_lock():
"""Create a user-level config read lock."""
from renku.core.util.contexts import Lock

lock_path = os.environ.get("RENKU_LOCK_PATH")
if lock_path is not None:
return Lock(Path(lock_path))

return Lock(project_context.global_config_path)


def global_config_write_lock():
"""Create a user-level config write lock."""
from renku.core.util.contexts import Lock

lock_path = os.environ.get("RENKU_LOCK_PATH")
if lock_path is not None:
return Lock(Path(lock_path), mode="exclusive")

return Lock(project_context.global_config_path, mode="exclusive")


Expand Down Expand Up @@ -112,7 +121,10 @@ def load_config(config_filter=ConfigFilter.ALL):
elif config_filter == ConfigFilter.GLOBAL_ONLY:
config_files += [project_context.global_config_path]
elif config_filter == ConfigFilter.ALL:
config_files += [project_context.global_config_path, project_context.local_config_path]
config_files += [
project_context.global_config_path,
project_context.local_config_path,
]

if config_filter != ConfigFilter.LOCAL_ONLY:
with global_config_read_lock():
Expand Down

0 comments on commit 050ed61

Please sign in to comment.