You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing a relative path, as str or Path object, generates a NotFoundException when resolving paths using the StaticFilesConfig class when it should be resolved correctly.
This is interesting, as the path will first be validated when instantiating the class by Pydantic with the DirectoryPath type (and a Path object created), but later when joining the directory and file_path it fails to resolve it correctly:
in base.py/get_fs_info [line 57]:
static_path = Path("../static").resolve() # or .absolute()
static = StaticFilesConfig(path="/ui", directories=[static_path])
A quick solution for this problem is to resolve() all given directories in StaticFiles:
class StaticFiles:
"""ASGI App that handles file sending."""
def __init__(
self,
directories: Sequence["PathType"],
) -> None:
"""Initialize the Application.
self.directories = [d.resolve() for d in directories] # <-- here
I think there may be a better solution using Pathlib joining instead of os.join that might involve more refactoring.
The text was updated successfully, but these errors were encountered:
Maxyme
changed the title
Bug: Passing relative Path to
Bug: Passing relative Path to StaticFilesConfig fails to join correctly but passes validation.
Mar 1, 2023
@Goldziher thanks for the reply. I just checked on main and it now works when passing a relative Path object, but not a str. (ie. Path("../static") works but not "../static")
Passing a relative path, as str or Path object, generates a NotFoundException when resolving paths using the StaticFilesConfig class when it should be resolved correctly.
This is interesting, as the path will first be validated when instantiating the class by Pydantic with the
DirectoryPath
type (and a Path object created), but later when joining the directory and file_path it fails to resolve it correctly:in base.py/get_fs_info [line 57]:
How to reproduce:
This returns a NotFoundException: "no file or directory match the path was found"
While this works fine:
A quick solution for this problem is to resolve() all given directories in StaticFiles:
I think there may be a better solution using Pathlib joining instead of os.join that might involve more refactoring.
The text was updated successfully, but these errors were encountered: