Skip to content

Commit 46d4e1e

Browse files
committed
fix: correctly identify intra-dataset basins via basin identifiers
1 parent 6d0d0a5 commit 46d4e1e

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
1.0.5
2+
- fix: correctly identify intra-dataset basins via basin identifiers
23
- fix: list all features available in intra-dataset basins
34
- fix: disable simple name-based basin check for intra-dataset basins
5+
- setup: bump dclab to 0.66.0
46
1.0.4
57
- fix: resolve self-referencing basin creation in background job
68
1.0.3

ckanext/dc_serve/jobs.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _get_intra_dataset_upstream_basins(res_dict, ds) -> list[dict]:
225225
else:
226226
basin_map = ds[map_data][:]
227227

228-
# check whether the file name is in the list of resources.
228+
# check whether the basin is in the list of resources.
229229
for res in pkg.resources:
230230
if _is_basin_of_dataset(ds, res, bn_dict):
231231
# upstream resource ID
@@ -300,6 +300,9 @@ def _is_basin_of_dataset(ds,
300300
):
301301
"""Check whether a CKAN resource is a basin for a dataset
302302
303+
Return True when `resource_basin` is a basin of `ds`
304+
as described by `basin_dict`.
305+
303306
Parameters
304307
----------
305308
ds:
@@ -313,26 +316,30 @@ def _is_basin_of_dataset(ds,
313316
ds_runid = ds.get_measurement_identifier()
314317
with get_dc_instance(resource_basin.id) as ds_bn:
315318
bn_runid = ds_bn.get_measurement_identifier()
319+
bn_runid_dict = basin_dict.get("identifier")
316320

317-
if not bn_runid:
321+
if not bn_runid or not bn_runid_dict:
318322
# No run identifier specified -> no basin inference possible.
319323
return False
320324

325+
if bn_runid != bn_runid_dict:
326+
# Basin-resource mismatch.
327+
# This resource is not the measurement referenced in this basin.
328+
return False
329+
321330
mapping_is_same = basin_dict.get("mapping", "same") == "same"
322331

323332
if mapping_is_same and bn_runid == ds_runid:
324333
# This is an ideal case. Both run identifiers match and the mapping
325334
# is identical.
326-
print(f"same {bn_runid} {ds_runid}")
327335
return True
328336

329-
elif not mapping_is_same and ds_runid.rsplit("_", 1)[0] == bn_runid:
330-
# This is a slightly more complicated cases. If you split the
331-
# run identifiers with an underscore (dclab 0.65.0 and dcnum 0.25.11
332-
# correctly support this), then the referrer has a run identifier
333-
# that starts with that of the basin.
334-
print(f"basinmap {bn_runid} {ds_runid}")
337+
elif not mapping_is_same and ds_runid.startswith(bn_runid):
338+
# This is a slightly more complicated cases. If the mapping
339+
# is not "same", this means that we have filtered datasets.
340+
# For a filtered dataset, the identifier is the identifier of
341+
# its basin plus a unique string.
335342
return True
336343

337-
# None of the above cases matched. This is not a basin of ds.
344+
# None of the above cases matched. This is not a direct basin of ds.
338345
return False

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
license = {text = "GNU Affero General Public License v3 or later (AGPLv3+)"}
2929
dependencies = [
3030
"ckan>=2.10.4, <3",
31-
"dclab>=0.65.0",
31+
"dclab>=0.66.0",
3232
"dcor_shared>=1.0.3",
3333
]
3434
dynamic = ["version"]

0 commit comments

Comments
 (0)