webdav4
webdav4 copied to clipboard
`client.exists()` returns `True` even if resource does not exists
Hi, I'm using your library to write some tests around a WebDav server. Thanks for making it open source. I am new to WebDav so if I am mistaken in understanding what's going on please let me know.
If I call client.exists() on a resource that does not exist inside an existing collection I always get True back.
This seems to be due to the fact that .propfind() always returns a result even if targeting a non-existing resource (in that case you can tell the resource does not exist because all the properties in result.responses["resource-name"].properties are None).
If the resource does not exist, the server should be returning 404 status, which is being checked here:
https://github.com/skshetry/webdav4/blob/45f9e42479164602be0f7fd55cecc6de8e7214b7/src/webdav4/client.py#L353-L354
207 response means it exists.
Could you please share the details about the server that you are using? We use a test WebDAV server which you can play with, or else use a real servers like Nextcloud/ownCloud/Apache. Please check the Contributing Guide.
I am using this docker image: https://hub.docker.com/r/ionelmc/webdav/.
I am using as a test environment a (local) Kubernetes deployment with two containers, one of the being the one running the webdav docker image above.
I have noticed another strange behaviour when I try to create a new collection using client.mkdir("some_collection") or client.mkdir("/some_collection") I get a 409 and an error message saying that the parent of the collection does not exist even though the parent (I assume it to be "/") should exists (and actually client.ls("/") returns meaningful results)
@Zigur, thanks I am able to reproduce. This issue happens because webdav4 does not add a trailing slash (it strips if the user passes a explicit trailing slash as well).
This is an issue with webdav4 that I'd like to fix at some point in time (see #3), but for now, I'll just patch mkdir to send a trailing slash query. :)
@Zigur, I fixed the mkdir issue and released 0.9.2. I am also able to reproduce the exists returning True on not-existing resources.
I'd argue that this is a bug on the WebDAV server that you are using, as all the HTTP stuff still applies to the WebDAV. So, like the HTTP servers, WebDAV servers should return 404 if the resource does not exist. Webdav spec is not very clear in this though.
I created #59 that supports Nginx dav extension, but this might affect other sane WebDAV servers, so I will probably not be releasing soon without further testing. You can try it out by using:
pip install git+https://github.com/skshetry/webdav4.git@nginx-compat#egg=webdav4[fsspec]
Let me know if you get any issues.