{"record":{"id":"e0d82712590c8558","repo":"apache/beam","slug":"expected-image-content-in-type-item-name-item-id-got-none","errorCode":null,"errorMessage":"Expected image content in {type(item).__name__} {item.id}, got None","messagePattern":"Expected image content in (.+?) (.+?), got None","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/rag/embeddings/huggingface.py","lineNumber":109,"sourceCode":"      self, **kwargs\n  ) -> beam.PTransform[beam.PCollection[EmbeddableItem],\n                       beam.PCollection[EmbeddableItem]]:\n    \"\"\"Returns PTransform that uses the RAG adapter.\"\"\"\n    return RunInference(\n        model_handler=_TextEmbeddingHandler(self),\n        inference_args=self.inference_args).with_output_types(EmbeddableItem)\n\n\ndef _extract_images(items: Sequence[EmbeddableItem]) -> list:\n  \"\"\"Extract images from items and convert to PIL.Image objects.\n\n  Supports raw bytes, local file paths, and remote URIs\n  (e.g. gs://, s3://) via Beam's FileSystems.\n  \"\"\"\n  images = []\n  for item in items:\n    if not item.content.image:\n      raise ValueError(\n          \"Expected image content in \"\n          f\"{type(item).__name__} {item.id}, \"\n          \"got None\")\n    img_data = item.content.image\n    if isinstance(img_data, bytes):\n      img = PILImage.open(io.BytesIO(img_data))\n    else:\n      with FileSystems.open(img_data, 'rb') as f:\n        img = PILImage.open(f)\n        img.load()\n    images.append(img.convert('RGB'))\n  return images\n\n\ndef _create_hf_image_adapter(\n) -> EmbeddingTypeAdapter[EmbeddableItem, EmbeddableItem]:\n  \"\"\"Creates adapter for HuggingFace image embedding.\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/rag/embeddings/huggingface.py#L91-L127","documentation":"_extract_images in apache_beam.ml.rag/embeddings huggingface module raises this ValueError when an EmbeddableItem in the batch has no content.image (None). The helper loads image bytes/paths for HuggingfaceImageEmbeddings, which requires actual image data per item, so image-less items are rejected with a message naming the item's type and id. It runs on workers inside the batching path at pipeline runtime.","triggerScenarios":"Passing items whose content.image was never populated (e.g. records built for text embedding, or source rows with null image columns/URIs) through HuggingfaceImageEmbeddings; upstream file reads silently failing and leaving image=None; mixing text and image items in one PCollection.","commonSituations":"Datasets with missing/placeholder image references; a key rename in the record-building step (image bytes stored under a different field); sending text documents to an image embeddings pipeline by mistake.","solutions":["Filter items without image data before the transform: beam.Filter(lambda x: x.content.image).","Fix the upstream step so content.image is populated with bytes, a local path, or a remote URI (gs://, s3://).","Use the text embeddings manager for text-only items.","Use the reported item.id to trace the bad record to its origin."],"exampleFix":"// before\nembedded = pcoll | image_embedder\n\n// after\nembedded = (pcoll\n    | beam.Filter(lambda item: item.content.image)\n    | image_embedder)","handlingStrategy":"validation","validationCode":"import apache_beam as beam\n\ndef filter_items_without_image(pcoll):\n    return pcoll | 'DropEmptyImage' >> beam.Filter(\n        lambda item: bool(item.content and item.content.image))","typeGuard":"def has_image(item) -> bool:\n    content = getattr(item, 'content', None)\n    return bool(content is not None and getattr(content, 'image', None))","tryCatchPattern":"try:\n    result = pcoll | image_embedder\nexcept ValueError as e:\n    # e.g. 'Expected image content in EmbeddableItem <id>, got None'\n    logging.error('Embedding input missing image: %s', e)\n    raise","preventionTips":["Filter out null image fields before image embedding transforms.","Validate image URIs/paths resolve (FileSystems.exists) during record building.","Use image-specific embeddings managers only for image-bearing PCollections."],"tags":["python","apache-beam","valueerror","embeddings","null-content"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}