Skip to content

fix: WilcoBundleFinder.find() returns empty string instead of None, breaks Django finders.find() #16

@hartym

Description

@hartym

Bug

WilcoBundleFinder.find(path, all=False) returns "" (empty string) when no file matches. This breaks Django's staticfiles.finders.find() aggregation.

Root cause

In wilco/bridges/django/finders.py, lines 55 and 69:

return [] if all else ""

Django's finders.find() iterates all finders and collects results:

for finder in get_finders():
    result = finder.find(path, all=all)
    if not all and result:
        return result
    if not isinstance(result, (list, tuple)):
        result = [result]
    matches.extend(result)
if matches:
    return matches
return [] if all else None

When all=False, the "" is falsy so it doesn't trigger early return. But then it gets wrapped into [""] and added to matches. Since [""] is truthy, finders.find() returns [""] instead of None.

Impact

Any middleware or tool that calls finders.find() receives [""] (a list) instead of None for non-wilco paths. For example, whitenoise 6.x calls finders.find() and then passes the result to os.path.exists(), which raises:

TypeError: stat: path should be string, bytes, os.PathLike or integer, not list

This only manifests when a static file is not found by any other finder (e.g. a hashed filename in development mode).

Suggested fix

Return None instead of "" when all=False:

# finders.py, line 55 and 69
return [] if all else None

This matches the convention used by Django's built-in finders (FileSystemFinder, AppDirectoriesFinder) which return the empty matches list for no-match with all=False, or a string path on match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions