Skip to content

[Bug]: [Python] LocalFileSystem.match() returns empty results for relative glob patterns in the current working directory #41375

Closed

Description

@jk-shah

What happened?

Calling FileSystems.match(['users.json*']) (or FileSystems.delete(['users.json*']) / fileio.MatchFiles('users.json*')) with a bare relative glob pattern in the current working directory (no directory separator) returns 0 matches even when matching files exist in os.getcwd(), whereas FileSystems.match(['./users.json*']) succeeds:

import os
import tempfile
from apache_beam.io.filesystems import FileSystems

with tempfile.TemporaryDirectory() as d:
  old_cwd = os.getcwd()
  os.chdir(d)
  try:
    with open('users.json-00000-of-00001', 'w') as f:
      f.write('{}\n')
    print(FileSystems.match(['users.json*'])[0].metadata_list)    # [] (expected 1 match)
    print(FileSystems.match(['./users.json*'])[0].metadata_list)  # [FileMetadata(./users.json-00000-of-00001, ...)]
  finally:
    os.chdir(old_cwd)

Cause

In FileSystem.match (sdks/python/apache_beam/io/filesystem.py, lines 742-759) and LocalFileSystem (sdks/python/apache_beam/io/localfilesystem.py, lines 87-125):

  1. For pattern = 'users.json*', prefix_or_dir is 'users.json'.
  2. self._url_dirname('users.json') calls os.path.dirname('users.json') (localfilesystem.py:96), returning ''.
  3. LocalFileSystem._list('') checks if not self.exists(dir_or_prefix): return (localfilesystem.py:113-114). Because os.path.exists('') is False, _list('') yields nothing.
  4. Note that if _list walks '.' when dir_or_prefix == '', the leading './' (or '.\' on Windows) prefix on yielded paths also needs to be stripped so self.match_files(file_metadatas, 'users.json*') matches the caller's relative pattern cleanly.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam ML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Infrastructure
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Prism Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner

Activity

  1. Naman-Katiyar commented on Nov 16, 2026

    @Naman-Katiyar

    .take-issue

    Hi, I would like to work on this issue. Could you please assign it to me?

  2. shikhabhadoria commented on Nov 16, 2026

    @shikhabhadoria
    Contributor

    .take-issue

  3. added this to the 2.79.0 Release milestone on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions