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

Bug: create_static_files_router with S3FS crashes due to unsupported fs info key (mtime) #3899

Closed
1 of 4 tasks
thomastu opened this issue Dec 12, 2024 · 3 comments · Fixed by #3902
Closed
1 of 4 tasks
Labels
Bug 🐛 This is something that is not working as expected

Comments

@thomastu
Copy link

thomastu commented Dec 12, 2024

Description

When using S3FS in a static router, ASGIFileResponse uses the mtime attribute on fs_info which is not consistently available across fssspec implementations (See: fsspec/filesystem_spec#526).

URL to code causing the issue

No response

MCVE

# Script Dependencies:
#     litestar
#     s3fs

from s3fs import S3FileSystem
from litestar import Litestar
from litestar.static_files import create_static_files_router

BUCKET_NAME = "some-s3-bucket"

app = Litestar(route_handlers=[
    create_static_files_router(
      path="/", 
      directories=[f"/{BUCKET_NAME}/"],
      html_mode=True,
      file_system=S3FileSystem()
    )
  ]
)

Steps to reproduce

1. Seed an s3 bucket with an index.html file
2. Run `litestar run`
3. Go to `localhost:8000`
4. See error

Screenshots

No response

Logs

INFO:     127.0.0.1:50567 - "GET / HTTP/1.1" 500 Internal Server Error
ERROR - 2024-12-12 14:44:08,439 - litestar - config - Uncaught exception (connection_type=http, path=/):
Traceback (most recent call last):
  File ".venv/lib/python3.12/site-packages/litestar/middleware/_internal/exceptions/middleware.py", line 159, in __call__
    await self.app(scope, receive, capture_response_started)
  File ".venv/lib/python3.12/site-packages/litestar/_asgi/asgi_router.py", line 100, in __call__
    await asgi_app(scope, receive, send)
  File ".venv/lib/python3.12/site-packages/litestar/routes/http.py", line 84, in handle
    await response(scope, receive, send)
  File ".venv/lib/python3.12/site-packages/litestar/response/base.py", line 194, in __call__
    await self.start_response(send=send)
  File ".venv/lib/python3.12/site-packages/litestar/response/file.py", line 220, in start_response
    self.headers.setdefault("last-modified", formatdate(fs_info["mtime"], usegmt=True))
                                                        ~~~~~~~^^^^^^^^^
KeyError: 'mtime'

Litestar Version

2.13.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@thomastu thomastu added the Bug 🐛 This is something that is not working as expected label Dec 12, 2024
@provinzkraut
Copy link
Member

Hmm. Using this comment as a reference, it seems that support for this varies wildly across different fsspec implementations, so does the key under which the value is provided. I'm not sure it's feasible to patch in special casing for every fsspec FS here. It would be much better if fsspec implemented a unified API to access this.

We could at least not make it fail in the meantime though.

Copy link

This issue has been closed in #3902. The change will be included in upcoming releases.

Copy link

github-actions bot commented Jan 8, 2025

A fix for this issue has been released in v2.14.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
2 participants