-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
pathlib.Path-alike no longer works in 3.9.0 for web.FileResponse #7928
Comments
If you'd like to make a PR to revert that section and include a test that exhibits the problem, we can probably include it. |
I created a draft PR. It needs some more thought and work. It just reverts the change, but that is not right solution because it also reverts support for all I'll probably add
The subclass of |
What's the actual data? Are you opening a file and just want to keep it open? It would not be terribly difficult to allow the constructor to also accept a file object, in particular an instance of |
It is not a file at all. It is in-memory generated media data that changes infrequently and has timestamp and content-type from the extension. I like to use the implementation of RFC 7232 and RFC 7233 that is in FileResponse. |
Describe the bug
I use
web.FileResponse
to respond with a file that is not really on the disk. This is done with aPath
instance that implements thepathlib.Path
interface. Much like thezipfile.Path
in the standard library. (zipfile.Path
has nostat
yet, so it is a no-go anyway.)With upgrade to 3.9.0, this no longer works, but it fails with file not found exception.
I see the change came in #7111, the backport of #6876. For no apparent reason, the condition to only replace str with
pathlib.Path
was changed to createpathlib.Path
for any argument.Python 3.12 is preparing for
pathlib.Path
to be subclassed more easily (see whatsnew). Whatever reasons there are to subclass, would also be broken by this kind of change.Since this breaks something that used to work, I report this as a bug. As a new feature it would not require much. Only
Path
membersname
,open
,stat
,with_name
andis_file
for the value returned bywith_name
.To Reproduce
pathlib.Path
like subclass.web.FileResponse
.Expected behavior
Response created with the stat and file content of the
pathlib.Path
.Logs/tracebacks
Python Version
aiohttp Version
multidict Version
yarl Version
OS
Related component
Server
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: