Skip to content

Commit 0dd4f41

Browse files
ethanwharristchatonotaj
authored andcommitted
Fix bug in upload file endpoint (#14924)
Co-authored-by: thomas chaton <[email protected]> Co-authored-by: otaj <[email protected]>
1 parent e780baa commit 0dd4f41

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/lightning_app/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2727
- CLI usage without arguments errors ([#14877](https://github.com/Lightning-AI/lightning/pull/14877))
2828

2929

30+
- Fixed a bug where the upload files endpoint would raise an error when running locally ([#14924](https://github.com/Lightning-AI/lightning/pull/14924))
31+
32+
3033
## [0.6.2] - 2022-09-21
3134

3235
### Changed

src/lightning_app/core/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from lightning_app.storage import Drive
2828
from lightning_app.utilities.app_helpers import InMemoryStateStore, Logger, StateStore
2929
from lightning_app.utilities.cloud import is_running_in_cloud
30-
from lightning_app.utilities.enum import OpenAPITags
30+
from lightning_app.utilities.component import _context
31+
from lightning_app.utilities.enum import ComponentContext, OpenAPITags
3132
from lightning_app.utilities.imports import _is_starsessions_available
3233

3334
if _is_starsessions_available():
@@ -256,7 +257,8 @@ async def upload_file(filename: str, uploaded_file: UploadFile = File(...)):
256257
f.write(content)
257258
done = content == b""
258259

259-
drive.put(filename)
260+
with _context(ComponentContext.WORK):
261+
drive.put(filename)
260262
return f"Successfully uploaded '{filename}' to the Drive"
261263

262264

tests/tests_app/core/test_lightning_api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def target():
431431

432432

433433
def test_configure_api():
434-
434+
# Setup
435435
process = Process(target=target)
436436
process.start()
437437
time_left = 15
@@ -443,6 +443,13 @@ def test_configure_api():
443443
sleep(0.1)
444444
time_left -= 0.1
445445

446+
# Test Upload File
447+
files = {"uploaded_file": open(__file__, "rb")}
448+
449+
response = requests.put(f"http://localhost:{APP_SERVER_PORT}/api/v1/upload_file/test", files=files)
450+
assert response.json() == "Successfully uploaded 'test' to the Drive"
451+
452+
# Test Custom Request
446453
response = requests.post(
447454
f"http://localhost:{APP_SERVER_PORT}/api/v1/request", data=InputRequestModel(name="hello").json()
448455
)
@@ -451,6 +458,8 @@ def test_configure_api():
451458
f"http://localhost:{APP_SERVER_PORT}/api/v1/request", data=InputRequestModel(name="hello").json()
452459
)
453460
assert response.json() == {"name": "hello", "counter": 2}
461+
462+
# Teardown
454463
time_left = 15
455464
while time_left > 0:
456465
if process.exitcode == 0:

0 commit comments

Comments
 (0)