Skip to content

Commit c9a38e9

Browse files
committed
Move copy operation to encure metadata isn't modified
1 parent 39ce9e8 commit c9a38e9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

caltechdata_api/caltechdata_edit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def caltechdata_edit(
6666
s3_link=None,
6767
default_preview=None,
6868
):
69+
# Make a copy of the metadata to make sure our local changes don't leak
70+
metadata = copy.deepcopy(metadata)
6971

7072
# If no token is provided, get from RDMTOK environment variable
7173
if not token:
@@ -198,7 +200,7 @@ def caltechdata_edit(
198200
}
199201
metadata["pids"] = pids
200202

201-
data = customize_schema.customize_schema(copy.deepcopy(metadata), schema=schema)
203+
data = customize_schema.customize_schema(metadata, schema=schema)
202204

203205
if files:
204206
if default_preview:

caltechdata_api/caltechdata_write.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def write_files_rdm(files, file_link, headers, f_headers, s3=None):
1919
if filename in fnames:
2020
# We can't have a duplicate filename
2121
# Assume that the previous path value makes a unique name
22-
filename = f"{split[-2]}-{split[-1]}"
22+
filename = f"{split[-2]}-{split[-1]}"
2323
fnames.append(filename)
2424
f_json.append({"key": filename})
2525
f_list[filename] = f
@@ -155,6 +155,9 @@ def caltechdata_write(
155155
156156
S3 is a s3sf object for directly opening files
157157
"""
158+
# Make a copy so that none of our changes leak out
159+
metadata = copy.deepcopy(metadata)
160+
158161
# If no token is provided, get from RDMTOK environment variable
159162
if not token:
160163
token = os.environ["RDMTOK"]
@@ -218,7 +221,7 @@ def caltechdata_write(
218221
metadata["pids"] = pids
219222

220223
if authors == False:
221-
data = customize_schema.customize_schema(copy.deepcopy(metadata), schema=schema)
224+
data = customize_schema.customize_schema(metadata, schema=schema)
222225
if production == True:
223226
url = "https://data.caltech.edu/"
224227
else:

0 commit comments

Comments
 (0)