villebro commented on a change in pull request #9047: [csv upload] Use python's 
named temp file
URL: 
https://github.com/apache/incubator-superset/pull/9047#discussion_r374774828
 
 

 ##########
 File path: superset/views/database/views.py
 ##########
 @@ -92,21 +106,23 @@ def form_post(self, form):
             flash(message, "danger")
             return redirect("/csvtodatabaseview/form")
 
-        csv_file = form.csv_file.data
-        form.csv_file.data.filename = 
secure_filename(form.csv_file.data.filename)
         csv_filename = form.csv_file.data.filename
-        path = os.path.join(config["UPLOAD_FOLDER"], csv_filename)
+        extension = os.path.splitext(csv_filename)[1].lower()
+        path = tempfile.NamedTemporaryFile(
+            dir=app.config["UPLOAD_FOLDER"], suffix=extension
+        ).name
 
 Review comment:
   Not sure if it makes any difference, but by default `NamedTemporaryFile` 
deletes the file after it is closed. I suppose it's ok to delete the file, too, 
but I think it should be safe to remove the `os.remove(path)`s below to keep 
the code lean.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to