Skip to content

Commit 6237dc7

Browse files
authored
fix(service): return proper errors on migrations check (#3334)
1 parent 9cbb465 commit 6237dc7

30 files changed

+494
-212
lines changed

poetry.lock

Lines changed: 28 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ zodb = "==5.8.0"
107107
zstandard = ">=0.16.0,<0.22.0"
108108

109109
# service dependencies:
110-
apispec = { version = ">=4.0.0,<5.3.0", optional = true }
110+
apispec = { version = ">=6.3.0,<6.4.0", optional = true }
111+
apispec-oneofschema = { version = ">=3.0.0,<4.0.0", optional = true}
111112
apispec-webframeworks = { version = "<0.6,>=0.5.2", optional = true }
112113
circus = { version = "==0.18.0", optional = true }
113114
flask = { version = "==2.2.5", optional = true }
@@ -173,6 +174,7 @@ sphinxcontrib-spelling = ">=7,<9"
173174
[tool.poetry.extras]
174175
service = [
175176
"apispec",
177+
"apispec-oneofschema",
176178
"apispec-webframeworks",
177179
"circus",
178180
"flask",
@@ -282,6 +284,7 @@ check_untyped_defs = true
282284
[[tool.mypy.overrides]]
283285
module = [
284286
"apispec.*",
287+
"apispec_oneofschema.*",
285288
"apispec_webframeworks.*",
286289
"appdirs",
287290
"BTrees.*",

renku/command/checks/activities.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def check_migrated_activity_ids(fix, activity_gateway: IActivityGateway, **_):
5858
wrong_activities = []
5959

6060
if not wrong_activities:
61-
return True, None
61+
return True, False, None
6262

6363
problems = (
6464
WARNING
@@ -68,7 +68,7 @@ def check_migrated_activity_ids(fix, activity_gateway: IActivityGateway, **_):
6868
+ "\n"
6969
)
7070

71-
return False, problems
71+
return False, True, problems
7272

7373

7474
@inject.autoparams("activity_gateway")
@@ -81,7 +81,8 @@ def check_activity_dates(fix, activity_gateway: IActivityGateway, **_):
8181
_: keyword arguments.
8282
8383
Returns:
84-
Tuple[bool, Optional[str]]: Tuple of whether there are activities with invalid dates a string of the problem.
84+
Tuple[bool, Optional[str]]: Tuple of whether there are activities with invalid dates, if they can be
85+
automatically fixed and a string of the problem.
8586
"""
8687
invalid_activities = []
8788

@@ -95,7 +96,7 @@ def check_activity_dates(fix, activity_gateway: IActivityGateway, **_):
9596
invalid_activities.append(activity)
9697

9798
if not invalid_activities:
98-
return True, None
99+
return True, False, None
99100
if not fix:
100101
ids = [a.id for a in invalid_activities]
101102
message = (
@@ -104,13 +105,13 @@ def check_activity_dates(fix, activity_gateway: IActivityGateway, **_):
104105
+ "\n\t"
105106
+ "\n\t".join(ids)
106107
)
107-
return False, message
108+
return False, True, message
108109

109110
fix_activity_dates(activities=invalid_activities)
110111
project_context.database.commit()
111112
communication.info("Activity dates were fixed")
112113

113-
return True, None
114+
return True, False, None
114115

115116

116117
def fix_activity_dates(activities):

renku/command/checks/datasets.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ def check_dataset_old_metadata_location(**_):
3838
_: keyword arguments.
3939
4040
Returns:
41-
Tuple of whether dataset metadata location is valid and string of found problems.
41+
Tuple of whether dataset metadata location is valid, if an automated fix is available and string of
42+
found problems.
4243
"""
4344
old_metadata = get_pre_0_3_4_datasets_metadata()
4445

4546
if not old_metadata:
46-
return True, None
47+
return True, False, None
4748

4849
problems = (
4950
WARNING + "There are metadata files in the old location."
@@ -52,7 +53,7 @@ def check_dataset_old_metadata_location(**_):
5253
+ "\n"
5354
)
5455

55-
return False, problems
56+
return False, False, problems
5657

5758

5859
@inject.autoparams("dataset_gateway")
@@ -64,7 +65,7 @@ def check_missing_files(dataset_gateway: IDatasetGateway, **_):
6465
_: keyword arguments.
6566
6667
Returns:
67-
Tuple of whether all dataset files are there and string of found problems.
68+
Tuple of whether all dataset files are there, if an automated fix is available and string of found problems.
6869
"""
6970
missing = defaultdict(list)
7071

@@ -79,7 +80,7 @@ def check_missing_files(dataset_gateway: IDatasetGateway, **_):
7980
missing[dataset.name].append(file_.entity.path)
8081

8182
if not missing:
82-
return True, None
83+
return True, False, None
8384

8485
problems = WARNING + "There are missing files in datasets."
8586

@@ -91,7 +92,7 @@ def check_missing_files(dataset_gateway: IDatasetGateway, **_):
9192
+ "\n\t ".join(click.style(path, fg="red") for path in files)
9293
)
9394

94-
return False, problems
95+
return False, False, problems
9596

9697

9798
@inject.autoparams("dataset_gateway")
@@ -104,7 +105,7 @@ def check_invalid_datasets_derivation(fix, dataset_gateway: IDatasetGateway, **_
104105
_: keyword arguments.
105106
106107
Returns:
107-
Tuple of whether dataset derivations are valid and string of found problems.
108+
Tuple of whether dataset derivations are valid, if an automated fix is available and string of found problems.
108109
"""
109110
invalid_datasets = []
110111

@@ -130,7 +131,7 @@ def fix_or_report(dataset):
130131
break
131132

132133
if not invalid_datasets:
133-
return True, None
134+
return True, False, None
134135

135136
problems = (
136137
WARNING
@@ -140,7 +141,7 @@ def fix_or_report(dataset):
140141
+ "\n"
141142
)
142143

143-
return False, problems
144+
return False, True, problems
144145

145146

146147
@inject.autoparams("dataset_gateway")
@@ -193,9 +194,9 @@ def check_dataset_files_outside_datadir(fix, dataset_gateway: IDatasetGateway, *
193194
+ "\n\t".join(click.style(file.entity.path, fg="yellow") for file in invalid_files)
194195
+ "\n"
195196
)
196-
return False, problems
197+
return False, True, problems
197198

198-
return True, None
199+
return True, False, None
199200

200201

201202
@inject.autoparams("dataset_gateway")
@@ -208,7 +209,7 @@ def check_external_files(fix, dataset_gateway: IDatasetGateway, **_):
208209
_: keyword arguments.
209210
210211
Returns:
211-
Tuple of whether no external files are found and string of found problems.
212+
Tuple of whether no external files are found, if an automated fix is available and string of found problems.
212213
"""
213214
from renku.core.dataset.dataset import file_unlink
214215

@@ -222,7 +223,7 @@ def check_external_files(fix, dataset_gateway: IDatasetGateway, **_):
222223
datasets[dataset.name].append(file)
223224

224225
if not external_files:
225-
return True, None
226+
return True, False, None
226227

227228
external_files_str = "\n\t".join(sorted(external_files))
228229

@@ -232,7 +233,7 @@ def check_external_files(fix, dataset_gateway: IDatasetGateway, **_):
232233
"Use 'renku dataset rm' or rerun 'renku doctor' with '--fix' flag to remove them:\n\t"
233234
f"{external_files_str}\n"
234235
)
235-
return False, problems
236+
return False, True, problems
236237

237238
communication.info(
238239
"The following external files were deleted from the project. You need to add them later manually using a "
@@ -242,4 +243,4 @@ def check_external_files(fix, dataset_gateway: IDatasetGateway, **_):
242243
for name, files in datasets.items():
243244
file_unlink(name=name, yes=True, dataset_files=files)
244245

245-
return True, None
246+
return True, False, None

renku/command/checks/githooks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def check_git_hooks_installed(**_):
4141
hook_path = get_hook_path(name=hook, path=project_context.path)
4242
if not hook_path.exists():
4343
message = WARNING + "Git hooks are not installed. " 'Use "renku githooks install" to install them. \n'
44-
return False, message
44+
return False, False, message
4545

4646
with hook_path.open() as file_:
4747
actual_hook = _extract_renku_hook(file_)
@@ -50,16 +50,16 @@ def check_git_hooks_installed(**_):
5050

5151
if not expected_hook:
5252
message = WARNING + "Cannot check for existence of Git hooks.\n"
53-
return False, message
53+
return False, False, message
5454

5555
if actual_hook != expected_hook:
5656
message = (
5757
WARNING + "Git hooks are outdated or not installed.\n"
5858
' (use "renku githooks install --force" to update them) \n'
5959
)
60-
return False, message
60+
return False, False, message
6161

62-
return True, None
62+
return True, False, None
6363

6464

6565
def _extract_renku_hook(file):

renku/command/checks/migration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def check_migration(**_):
2626
_: keyword arguments.
2727
2828
Returns:
29-
Tuple of whether project metadata is up to date and string of found problems.
29+
Tuple of whether project metadata is up to date, if an automated fix is available and string of found problems.
3030
"""
3131
if is_migration_required():
3232
problems = WARNING + "Project requires migration.\n" + ' (use "renku migrate" to fix this issue)\n'
@@ -35,6 +35,6 @@ def check_migration(**_):
3535
ERROR + "Project version is not supported by your version of Renku.\n" + " (upgrade your Renku version)\n"
3636
)
3737
else:
38-
return True, None
38+
return True, False, None
3939

40-
return False, problems
40+
return False, False, problems

renku/command/checks/project.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def check_project_id_group(fix, project_gateway: IProjectGateway, **_):
3333
_: keyword arguments.
3434
3535
Returns:
36-
Tuple of whether project id is valid.
36+
Tuple of whether project id is valid, if an automated fix is available and string of found problems.
3737
"""
3838
current_project = project_gateway.get_project()
3939

@@ -42,21 +42,25 @@ def check_project_id_group(fix, project_gateway: IProjectGateway, **_):
4242
)
4343

4444
if namespace is None or name is None:
45-
return True, None
45+
return True, False, None
4646

4747
generated_id = Project.generate_id(namespace=namespace, name=name)
4848

4949
if generated_id == current_project.id:
50-
return True, None
50+
return True, False, None
5151

5252
if fix:
5353
communication.info(f"Fixing project id '{current_project.id}' -> '{generated_id}'")
5454
current_project.id = generated_id
5555
project_gateway.update_project(current_project)
56-
return True, None
56+
return True, False, None
5757

58-
return True, (
59-
WARNING
60-
+ "Project id doesn't match id created based on the current Git remote (use 'renku doctor --fix' to fix it):"
61-
f"\n\t'{current_project.id}' -> '{generated_id}'"
58+
return (
59+
False,
60+
True,
61+
(
62+
WARNING
63+
+ "Project id doesn't match id based on the current Git remote (use 'renku doctor --fix' to fix it):"
64+
f"\n\t'{current_project.id}' -> '{generated_id}'"
65+
),
6266
)

renku/command/checks/storage.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ def check_lfs_info(**_):
2626
_: keyword arguments.
2727
2828
Returns:
29-
Tuple of whether project structure is valid and string of found problems.
29+
Tuple of whether project structure is valid, if an automated fix is available and string of found problems.
3030
"""
3131
if not check_external_storage():
32-
return True, None
32+
return True, False, None
3333

3434
files = check_lfs_migrate_info()
3535

3636
if not files:
37-
return True, None
37+
return True, False, None
3838

3939
message = (
4040
WARNING
4141
+ "Git history contains large files - consider moving them "
42-
+ "to external storage like git LFS\n\t"
42+
+ "to external storage like git LFS using 'renku storage migrate'\n\t"
4343
+ "\n\t".join(files)
4444
+ "\n"
4545
)
4646

47-
return False, message
47+
return False, False, message

0 commit comments

Comments
 (0)