﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37557	InMemoryStorage raises ValueError instead of FileExistsError for paths nested below a file	Manoj	Manoj	"`InMemoryStorage` raises `FileExistsError` when a path traverses a file node (see `test_file_node_cannot_have_children`), but only when the file is the second-to-last path component:

{{{#!python
s = InMemoryStorage()
s.save(""file.txt"", ContentFile(""x""))
s.exists(""file.txt/a"")    # FileExistsError
s.exists(""file.txt/a/b"")  # ValueError: tuple.index(x): x not in tuple
}}}

`InMemoryDirNode.resolve()` builds the error path from `os.path.split(path)`, which returns a `(head, tail)` pair rather than the path segments, then calls `.index()` on it. This only works when the offending segment is the last component of the path. `listdir()`, `save()` and `open()` go through the same code path. The same code has been there since `InMemoryStorage` was added in 4.2.

I have a patch and will open a pull request.

Separately, and not addressed by the patch: `FileSystemStorage.exists()` returns `False` for these paths, while `InMemoryStorage.exists()` raises `FileExistsError`. Happy to open a separate ticket if that is worth discussing."	Bug	assigned	File uploads/storage	dev	Normal		storage		Unreviewed	1	0	0	0	0	0
