Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix file upload on windows #45

Merged
merged 2 commits into from
May 17, 2023
Merged

Conversation

NateVolt
Copy link
Contributor

closes #38

I did some digging and this seems to be a recurring theme with tempfile.NamedTemporaryFile() not being completely cross-platform. According to the python docs you can't open a tempfile more than once on windows.

Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows).

I aimed to make the minimum viable change that would fix the issue. All I have done here is to disable automatic cleanup and then clean it up manually. Some commenters on S.O. suggested rolling your own to avoid the cross-platform issues. According to official python docs os.remove() is fully cross-platform. However, I see that this is built on top of langchain, which seems to make heavy use of tempfile.NamedTemporaryFile() so it may not be feasible to migrate to a different file handling approach. I haven't scanned the rest of the Quivr codebase yet, but if this is the only place where file I/O occurs then this patch might be enough to close the books on this.

I tested on my machine by uploading a csv, txt, and pdf. I watched as each file was placed in the temp directory and then saw each get cleaned up.

Sidenote: I am not a python expert, so maybe this is normal, but I would expect tmp_file to be out of scope upon exiting the with block. However, I had no issues using it after exiting that scope. Anyone see anything concerning here?

@vercel
Copy link

vercel bot commented May 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quiver ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2023 6:04pm

@NateVolt NateVolt changed the title defer marking temp file for deletion fix file upload on windows May 17, 2023
@StanGirard
Copy link
Collaborator

Thanks a lot for your contribution. Really smart and simple ! It works on macos :)

@StanGirard StanGirard merged commit 5463bb3 into QuivrHQ:main May 17, 2023
Shaunwei pushed a commit to Shaunwei/quiver that referenced this pull request May 20, 2023
* defer marking temp file for deletion

closes QuivrHQ#38

* manually delete file
StanGirard pushed a commit that referenced this pull request Sep 12, 2023
* defer marking temp file for deletion

closes #38

* manually delete file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error uploading files on Windows
2 participants