mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-21 17:45:23 -04:00
langgenius / mineru cannot access local variable 'result_item' #705
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @llauren48 on GitHub (Oct 11, 2025).
Self Checks
Dify version
1.9.0
Plugin version
0.5.0
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
mineru version 2.5.4
dify version 1.9.0
mineru pulgin version 0.5.0
process the pdf from uploaded file would occur the error that "cannot access local variable 'result_item' where it is not associated with a value" in the following picture.
✔️ Error log
@dosubot[bot] commented on GitHub (Oct 11, 2025):
Hi @llauren48! I'm Dosu and I’m helping the dify-official-plugins team.
This error happens because in the Mineru plugin's PDF parsing code, the variable result_item is only defined inside a for loop over results.items(). If results is empty (for example, if the Mineru backend returns no results for a PDF), the loop never runs and result_item is never assigned. After the loop, the code tries to yield result_item, which triggers the UnboundLocalError you saw.
To fix this, you can either initialize result_item before the loop, or (preferably) only yield it if it was actually assigned during the loop. For example, you could add a check after the loop:
Or, initialize result_item to a default value before the loop. This will prevent the error when results is empty and make the plugin more robust when handling PDFs that produce no output from Mineru.
You can see the relevant code and the cause of the bug here: Mineru plugin parse.py.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

@llauren48 commented on GitHub (Oct 11, 2025):
As you can see in the picture, if I use the api to process the same pdf, the response already reply the results. So the error is not caused by the empty results, it may be is the reason of the inside logical error of getting value.
Here is the link for the test pdf: test1.pdf
@dosubot[bot] commented on GitHub (Oct 11, 2025):
You're right—the error isn't caused by empty results. The plugin's code assigns
result_iteminside a loop overresults.items(), but if the loop doesn't run (for example, if the plugin receives an unexpected data structure or the results key is missing),result_itemisn't assigned and the error occurs when it's accessed after the loop. Your API test shows the backend returns valid results for the same PDF, so the bug is likely in how the plugin parses or accesses the response, not in the backend or file content.To fix this, update the plugin code to only yield
result_itemif it was assigned during the loop. For example, after the loop, check ifresult_itemexists before yielding:Or, initialize
result_itemto a default value before the loop. This will prevent the error and make the plugin more robust when handling PDFs that produce output from Mineru. You can review the relevant code and logic here: Mineru plugin parse.py.If you still see the error even when results are present, double-check that the plugin receives the same data structure as the API response. There could be a mismatch in how the response is delivered to the plugin during runtime.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
