dify - 💡(How to fix) Fix [1.14.0 regression] file_service.upload_file fails with "Upload file <uuid> not found" when scoped FileAccessController is active [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

Root cause

Fix Action

Fixed

RAW_BUFFERClick to expand / collapse

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

1.14.0 (latest stable, released 2026-04-29)

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Have a workflow that internally creates a file via file_service.upload_file() during execution (e.g. a Workflow Tool that returns file output, or any workflow that materializes computed data as an upload_file).
  2. Run the workflow.
  3. Workflow fails with ValueError: Upload file <uuid> not found.

✔️ Expected Behavior

The internally generated upload should commit successfully and the workflow should proceed to subsequent nodes.

❌ Actual Behavior

Stack trace from docker-api-1: File "/app/api/services/file_service.py", line 113, in upload_file upload_file.source_url = file_helpers.get_signed_file_url(upload_file_id=upload_file.id) File "/app/api/core/app/workflow/file_runtime.py", line 96, in resolve_upload_file_url self._assert_upload_file_access(upload_file_id=upload_file_id) File "/app/api/core/app/workflow/file_runtime.py", line 172, in _assert_upload_file_access raise ValueError(f"Upload file {upload_file_id} not found") ValueError: Upload file 0e3996da-0f79-4f70-a1a8-4c26a5520aa6 not found

Root cause

In api/services/file_service.py upload_file() method, the source_url is generated before the new UploadFile row is committed to DB:

# CURRENT (buggy)
if not upload_file.source_url:
    upload_file.source_url = file_helpers.get_signed_file_url(upload_file_id=upload_file.id)
    # ↑ Calls _assert_upload_file_access() which queries DB → row not yet inserted → raises "not found"

with self._session_maker(expire_on_commit=False) as session:
    session.add(upload_file)
    session.commit()  # ← Commit happens AFTER

_assert_upload_file_access() in file_runtime.py only fires when current_scope() is not None, which is the case during workflow runtime execution. So the
bug only manifests when:
1. A workflow is being executed (FileAccessController scope is active), AND
2. That execution calls file_service.upload_file() on a fresh new file.

This is why /v1/files/upload (no scope) sometimes works while internal workflow upload (with scope) always fails.


Suggested fix

Swap the order: commit first, then generate source_url:

with self._session_maker(expire_on_commit=False) as session:
    session.add(upload_file)
    session.commit()  # ← commit FIRST so the row exists for assertion

if not upload_file.source_url:
    upload_file.source_url = file_helpers.get_signed_file_url(upload_file_id=upload_file.id)
    with self._session_maker(expire_on_commit=False) as session:
        session.merge(upload_file)
        session.commit()


Related

Closes / supersedes #35764 (same root cause, different surface symptom).


Affected scope

- ❌ Workflow runtime internal file uploads
- ❌ Workflow Tool execution that returns file outputs
- ✅ Knowledge Base / Dataset upload (verified working)
- ✅ Existing pgvector embedding / RAG search


Reproduction frequency

6 occurrences in 6 hours under normal usage.


Environment

Docker Compose deployment, GCE Ubuntu 22.04, external Cloud SQL pgvector 0.8.1, Cloud Run reverse proxy.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING