Skip to content

DOCX extraction silently drops embedded images without image in their part name #44904

Closed

Description

@Winoren

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

Current main 80265fcfe110f0aea056fcb3566d322986014b78 (API package 1.18.0).

Cloud or Self Hosted

Self Hosted (Source). Reproduced against the production WordExtractor using a saved and reloaded DOCX package, not a deployed knowledge-base instance.

Steps to reproduce

Create a valid DOCX with a drawing that embeds a PNG through an image relationship whose target is word/media/logo.png. The image bytes and relationship type remain valid; the part name simply does not contain the substring image.

A minimal way to build such a package using python-docx and Pillow:

from io import BytesIO
from docx import Document
from docx.opc.constants import RELATIONSHIP_TYPE as RT
from docx.opc.packuri import PackURI
from PIL import Image

png = BytesIO()
Image.new('RGB', (2, 2), 'red').save(png, format='PNG')
png.seek(0)
doc = Document()
doc.add_paragraph('Before logo')
doc.add_picture(png)
doc.add_paragraph('After logo')
rel = next(r for r in doc.part.rels.values() if r.reltype == RT.IMAGE)
rel.target_part._partname = PackURI('/word/media/logo.png')
doc.save('logo.docx')

Reloading the saved document with python-docx finds one inline drawing and the RT.IMAGE relationship targeting media/logo.png. Run WordExtractor('logo.docx', tenant_id, user_id, session=session).extract() with the usual storage/session dependencies.

✔️ Expected Behavior

The extractor stores the embedded PNG and includes its image-preview Markdown link between the surrounding paragraphs, regardless of whether the part name contains image.

❌ Actual Behavior

The production extractor returns only the surrounding paragraphs, with no image link or extracted image asset. _extract_images_from_docx() selects relationships using if "image" in rel.target_ref instead of the relationship type. The name-based check silently skips the valid media/logo.png relationship. Conversely, it also classifies non-image relationships as images when their target contains that substring.

Local output from the saved/reloaded package:

{
  "target": "media/logo.png",
  "loaded_inline_shapes": 1,
  "extracted": "Before logo\n\n\nAfter logo",
  "image_link_present": false
}

From Codex

Activity

  1. dosubot commented on Oct 27, 2026

    @dosubot

    One additional scope detail: the filename check runs before the embedded/external branch, so external image relationships whose URLs lack image are skipped too, before any download is attempted. Both paragraph and table-cell rendering then omit images absent from image_map. [1] [2] [3]

    The existing extraction test uses image1.png and https://example.com/image.png, so both fixtures pass the substring check and do not exercise this case. Your saved/reloaded logo.png reproduction would make useful regression coverage, alongside an external image URL without image and a non-image relationship whose target contains it. [4]

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about dify with Dosu

  2. added
    1.18.0
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.18.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions