Skip to content

Commit 4700fbe

Browse files
authored
Ensure pack() produces original documents, not internally updated (#1259)
1 parent a70a83f commit 4700fbe

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

cwltool/load_tool.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ def resolve_and_validate_document(
348348

349349
_convert_stdstreams_to_files(workflowobj)
350350

351+
if isinstance(jobobj, CommentedMap):
352+
loadingContext.jobdefaults = jobobj
353+
354+
loadingContext.loader = document_loader
355+
loadingContext.avsc_names = avsc_names
356+
loadingContext.metadata = metadata
357+
351358
if preprocess_only:
352359
return loadingContext, uri
353360

@@ -373,13 +380,6 @@ def update_index(pr: CommentedMap) -> None:
373380
processobj, ("CommandLineTool", "Workflow", "ExpressionTool"), update_index
374381
)
375382

376-
if isinstance(jobobj, CommentedMap):
377-
loadingContext.jobdefaults = jobobj
378-
379-
loadingContext.loader = document_loader
380-
loadingContext.avsc_names = avsc_names
381-
loadingContext.metadata = metadata
382-
383383
return loadingContext, uri
384384

385385

cwltool/pack.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from schema_salad.sourceline import cmap
2121

2222
from .process import shortname, uniquename
23+
from .context import LoadingContext
24+
from .load_tool import fetch_document, resolve_and_validate_document
2325

2426

2527
def flatten_deps(d, files): # type: (Any, Set[str]) -> None
@@ -121,14 +123,37 @@ def import_embed(d, seen):
121123

122124
def pack(
123125
document_loader: Loader,
124-
processobj, # type: Union[Dict[str, Any], List[Dict[str, Any]]]
126+
startingobj, # type: Union[Dict[str, Any], List[Dict[str, Any]]]
125127
uri, # type: str
126128
metadata, # type: Dict[str, str]
127129
rewrite_out=None, # type: Optional[Dict[str, str]]
128130
): # type: (...) -> Dict[str, Any]
129131

132+
# The workflow document we have in memory right now may have been
133+
# updated to the internal CWL version. We need to reload the
134+
# document to go back to its original version.
135+
#
136+
# What's going on here is that the updater replaces the
137+
# documents/fragments in the index with updated ones, the
138+
# index is also used as a cache, so we need to go through the
139+
# loading process with an empty index and updating turned off
140+
# so we have the original un-updated documents.
141+
#
130142
document_loader = SubLoader(document_loader)
131-
document_loader.idx = {}
143+
loadingContext = LoadingContext()
144+
loadingContext.do_update = False
145+
loadingContext.loader = document_loader
146+
loadingContext.loader.idx = {}
147+
loadingContext.metadata = {}
148+
loadingContext, docobj, uri = fetch_document(uri, loadingContext)
149+
loadingContext, uri = resolve_and_validate_document(
150+
loadingContext, docobj, uri, preprocess_only=True
151+
)
152+
if loadingContext.loader is None:
153+
raise Exception("loadingContext.loader cannot be none")
154+
processobj, metadata = loadingContext.loader.resolve_ref(uri)
155+
document_loader = loadingContext.loader
156+
132157
if isinstance(processobj, MutableMapping):
133158
document_loader.idx[processobj["id"]] = CommentedMap(processobj.items())
134159
elif isinstance(processobj, MutableSequence):

0 commit comments

Comments
 (0)