apache/beam · error · RuntimeError

Qdrant client is not initialized

Error message

Qdrant client is not initialized

What it means

_flush() performs the actual Qdrant upsert using self._client. The client is created lazily in setUp/process (inside the DoFn runtime); if _flush is reached while _client is still None, the DoFn's internal invariant is broken and it raises RuntimeError instead of crashing the client call.

Solutions

  1. In tests, call dofn.setup() before processing elements (or use the transform via a proper pipeline/test pipeline)
  2. Ensure any subclass override of setup() calls super().setup() so _client is initialized
  3. Use a TestPipeline / beam.test pipeline so the runner runs the full DoFn lifecycle
  4. If client creation depends on config, verify the config is valid so setup() doesn't silently skip client creation

Example fix

// before
dofn = _QdrantWriteFn(config)
dofn.process(item)
// after
dofn = _QdrantWriteFn(config)
dofn.setup()
dofn.process(item)
Defensive patterns

Strategy: try-catch

Validate before calling

# in tests, before calling process/finish_bundle:
dofn.setup()
assert dofn._client is not None

Type guard

def is_ready(dofn) -> bool:
    return getattr(dofn, "_client", None) is not None

Try / catch

try:
    dofn.finish_bundle()
except RuntimeError as e:
    if "not initialized" in str(e):
        dofn.setup()
        dofn.finish_bundle()
    else:
        raise

Prevention

When it happens

Trigger: Calling _flush() (via process or finish_bundle) on a _QdrantWriteTransform DoFn instance that never ran setUp / setup() — e.g. direct unit-test invocation of process/finish_bundle without setup, or a subclass overriding setup without initializing _client.

Common situations: Testing the DoFn directly without invoking setup(); runners or wrappers that skip DoFn lifecycle methods; custom subclasses of the transform that bypass client initialization.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/861dab32a53272db. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/ml/rag/ingestion/qdrant.py:297

        check_compatibility=False,
        **params.kwargs,
    )

  def teardown(self):
    if self._client:
      try:
        self._client.close()
      finally:
        self._client = None

  def finish_bundle(self):
    self._flush()

  def _flush(self):
    if not self._batch:
      return
    if not self._client:
      raise RuntimeError("Qdrant client is not initialized")

    max_retries = 3
    attempt = 1
    while True:
      try:
        self._client.upsert(
            collection_name=self.config.collection_name,
            points=self._batch,
            timeout=self.config.timeout,
            **self.config.kwargs,
        )
        break
      except ResourceExhaustedResponse as e:
        time.sleep(e.retry_after_s)
        # don't count rate-limit against max_retries
        continue
      except (UnexpectedResponse, ResponseHandlingException,
              grpc.RpcError) as e:

View on GitHub (pinned to 12126d8942)