apache/beam · error · ValueError
Sleep seconds, if received, must be int. But received: %r
Error message
Sleep seconds, if received, must be int. But received: %r, %s
What it means
FileBasedOutputVerifier's __init__ accepts an optional sleep_secs used to wait for output files to become ready on the filesystem. It strictly requires int (or None); any other numeric type like float raises ValueError, since fractional wait seconds are not accepted.
Solutions
- Pass an int literal, e.g. sleep_secs=10, or None
- Convert explicitly with int() when the value comes from options/config
- If fractional precision is needed, scale the unit (e.g. milliseconds) instead
Example fix
// before verifier = FileBasedOutputVerifier(output, sleep_secs=2.5) // after verifier = FileBasedOutputVerifier(output, sleep_secs=int(2.5)) or sleep_secs=2
Defensive patterns
Strategy: type-guard
Validate before calling
if sleep_secs is not None and not isinstance(sleep_secs, int):
raise TypeError('sleep_secs must be int or None') Type guard
def is_valid_sleep_secs(v):
return v is None or isinstance(v, int) Try / catch
try:
verifier = FileBasedOutputVerifier(path, sleep_secs=sleep_secs)
except ValueError as e:
_LOGGER.warning('Bad sleep_secs: %s; defaulting to None', e)
verifier = FileBasedOutputVerifier(path) Prevention
- Coerce option values with int() before constructing verifiers
- Remember booleans are ints in Python — avoid passing flags
- Write tests covering verifier construction with option-sourced values
When it happens
Trigger: Constructing the verifier with sleep_secs=1.5, a string like '10', or any non-int value parsed from pipeline options.
Common situations: Passing a float from config parsing (options often come as strings/floats); forgetting that even 10.0 is a float and therefore rejected.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- A sink must inherit iobase.Sink, iobase.NativeSink, or be a…
- apache_beam.io.gcp.datastore.v1new.datastoreio.Entity…
- apache_beam.io.gcp.datastore.v1new.datastoreio.Key…
- cannot convert to micro seconds
- cannot convert the micro seconds to
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/aa1f833525282ff1.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/testing/pipeline_verifiers.py:103
Use apache_beam.io.filebasedsink to fetch file(s) from given path.
File checksum is a hash string computed from content of file(s).
"""
def __init__(self, file_path, expected_checksum, sleep_secs=None):
"""Initialize a FileChecksumMatcher object
Args:
file_path : A string that is the full path of output file. This path
can contain globs.
expected_checksum : A hash string that is computed from expected
result.
sleep_secs : Number of seconds to wait before verification start.
Extra time are given to make sure output files are ready on FS.
"""
if sleep_secs is not None:
if isinstance(sleep_secs, int):
self.sleep_secs = sleep_secs
else:
raise ValueError(
'Sleep seconds, if received, must be int. '
'But received: %r, %s' % (sleep_secs, type(sleep_secs)))
else:
self.sleep_secs = None
self.file_path = file_path
self.expected_checksum = expected_checksum
@retry.with_exponential_backoff(
num_retries=MAX_RETRIES, retry_filter=retry_on_io_error_and_server_error)
def _read_with_retry(self):
"""Read path with retry if I/O failed"""
read_lines = []
match_result = FileSystems.match([self.file_path])[0]
matched_path = [f.path for f in match_result.metadata_list]
if not matched_path:
raise IOError('No such file or directory: %s' % self.file_path)
View on GitHub (pinned to 12126d8942)