Skip to content

Commit 5d3c22d

Browse files
committed
Check is_valid_upload_filename method earlier
1 parent 5c4abde commit 5d3c22d

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

drucker/drucker_dashboard_servicer.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,20 @@ def UploadModel(self,
122122
) -> drucker_pb2.ModelResponse:
123123
""" Upload your latest ML model.
124124
"""
125-
save_path = None
125+
first_req = next(request_iterator)
126+
save_path = first_req.path
127+
if not self.is_valid_upload_filename(save_path):
128+
raise Exception(f'Error: Invalid model path specified -> {save_path}')
129+
126130
tmp_path = self.app.get_model_path(uuid.uuid4().hex)
127131
Path(tmp_path).parent.mkdir(parents=True, exist_ok=True)
128132
with open(tmp_path, 'wb') as f:
133+
f.write(first_req.data)
129134
for request in request_iterator:
130-
save_path = request.path
131-
model_data = request.data
132-
f.write(model_data)
135+
f.write(request.data)
136+
del first_req
133137
f.close()
134-
if not self.is_valid_upload_filename(save_path):
135-
raise Exception(f'Error: Invalid model path specified -> {save_path}')
138+
136139
model_path = self.app.get_model_path(save_path)
137140
Path(model_path).parent.mkdir(parents=True, exist_ok=True)
138141
shutil.move(tmp_path, model_path)

0 commit comments

Comments
 (0)