File upload failed #7093

Closed
opened 2026-02-21 18:18:53 -05:00 by yindo · 2 comments
Owner

Originally created by @yanzu888 on GitHub (Dec 6, 2024).

Self Checks

  • 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 (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

v0.12.1,v0.13.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Failed to upload local images in the chat group, I failed both v0.12.1 and v0.13.1

✔️ Expected Behavior

Upload pictures in chat groups

Actual Behavior

docker-api-1 error log:

2024-12-06 11:18:42.030 ERROR [Dummy-1] [app.py:875] - Exception on /console/api/files/upload [POST]
Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.UndefinedColumn: column "source_url" of relation "upload_files" does not exist
LINE 1: ...ted_by, created_at, used, used_by, used_at, hash, source_url...
                                                             ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper
    resp = resource(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
    resp = meth(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/console/wraps.py", line 142, in decorated
    return view(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/libs/login.py", line 92, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/console/wraps.py", line 26, in decorated
    return view(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 696, in wrapper
    resp = f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/console/wraps.py", line 85, in decorated
    return view(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/console/files.py", line 65, in post
    upload_file = FileService.upload_file(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/services/file_service.py", line 87, in upload_file
    db.session.commit()
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/scoping.py", line 597, in commit
    return self._proxied.commit()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2028, in commit
    trans.commit(_to_root=True)
  File "<string>", line 2, in commit
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1313, in commit
    self._prepare_impl()
  File "<string>", line 2, in _prepare_impl
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1288, in _prepare_impl
    self.session.flush()
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4352, in flush
    self._flush(objects)
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4487, in _flush
    with util.safe_reraise():
         ^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4448, in _flush
    flush_context.execute()
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 466, in execute
    rec.execute(self)
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 642, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 93, in save_obj
    _emit_insert_statements(
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 1233, in _emit_insert_statements
    result = connection.execute(
             ^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1418, in execute
    return meth(
           ^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
    return self._exec_single_context(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
    self._handle_dbapi_exception(
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column "source_url" of relation "upload_files" does not exist
LINE 1: ...ted_by, created_at, used, used_by, used_at, hash, source_url...
                                                             ^

[SQL: INSERT INTO upload_files (tenant_id, storage_type, key, name, size, extension, mime_type, created_by_role, created_by, created_at, used, used_by, used_at, hash, source_url) VALUES (%(tenant_id)s::UUID, %(storage_type)s, %(key)s, %(name)s, %(size)s, %(extension)s, %(mime_type)s, %(created_by_role)s, %(created_by)s::UUID, %(created_at)s, %(used)s, %(used_by)s::UUID, %(used_at)s, %(hash)s, %(source_url)s) RETURNING upload_files.id]
[parameters: {'tenant_id': '52cb0a76-f4da-4a1b-b4dc-a7a4b06ace5f', 'storage_type': 'local', 'key': 'upload_files/52cb0a76-f4da-4a1b-b4dc-a7a4b06ace5f/5fe9423c-5000-48cc-8e7e-5bdcade976ba.png', 'name': 'image.png', 'size': 309738, 'extension': 'png', 'mime_type': 'image/png', 'created_by_role': 'account', 'created_by': '2fa5269a-43be-4092-a82c-44e2a0e3d81b', 'created_at': datetime.datetime(2024, 12, 6, 11, 18, 42, 27112), 'used': False, 'used_by': None, 'used_at': None, 'hash': 'd17a7b6ecb08c68454d4ecbe365015144297e46a1aad314e3f526df4b906682e', 'source_url': ''}]
(Background on this error at: https://sqlalche.me/e/20/f405)

image

Originally created by @yanzu888 on GitHub (Dec 6, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version v0.12.1,v0.13.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Failed to upload local images in the chat group, I failed both v0.12.1 and v0.13.1 ### ✔️ Expected Behavior Upload pictures in chat groups ### ❌ Actual Behavior docker-api-1 error log: ``` 2024-12-06 11:18:42.030 ERROR [Dummy-1] [app.py:875] - Exception on /console/api/files/upload [POST] Traceback (most recent call last): File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context self.dialect.do_execute( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute cursor.execute(statement, parameters) psycopg2.errors.UndefinedColumn: column "source_url" of relation "upload_files" does not exist LINE 1: ...ted_by, created_at, used, used_by, used_at, hash, source_url... ^ The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper resp = resource(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request resp = meth(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/console/wraps.py", line 142, in decorated return view(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/libs/login.py", line 92, in decorated_view return current_app.ensure_sync(func)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/console/wraps.py", line 26, in decorated return view(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 696, in wrapper resp = f(*args, **kwargs) ^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/console/wraps.py", line 85, in decorated return view(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/console/files.py", line 65, in post upload_file = FileService.upload_file( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/services/file_service.py", line 87, in upload_file db.session.commit() File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/scoping.py", line 597, in commit return self._proxied.commit() ^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2028, in commit trans.commit(_to_root=True) File "<string>", line 2, in commit File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go ret_value = fn(self, *arg, **kw) ^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1313, in commit self._prepare_impl() File "<string>", line 2, in _prepare_impl File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go ret_value = fn(self, *arg, **kw) ^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1288, in _prepare_impl self.session.flush() File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4352, in flush self._flush(objects) File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4487, in _flush with util.safe_reraise(): ^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ raise exc_value.with_traceback(exc_tb) File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4448, in _flush flush_context.execute() File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 466, in execute rec.execute(self) File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 642, in execute util.preloaded.orm_persistence.save_obj( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 93, in save_obj _emit_insert_statements( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 1233, in _emit_insert_statements result = connection.execute( ^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1418, in execute return meth( ^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection return connection._execute_clauseelement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement ret = self._execute_context( ^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context return self._exec_single_context( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context self._handle_dbapi_exception( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception raise sqlalchemy_exception.with_traceback(exc_info[2]) from e File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context self.dialect.do_execute( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column "source_url" of relation "upload_files" does not exist LINE 1: ...ted_by, created_at, used, used_by, used_at, hash, source_url... ^ [SQL: INSERT INTO upload_files (tenant_id, storage_type, key, name, size, extension, mime_type, created_by_role, created_by, created_at, used, used_by, used_at, hash, source_url) VALUES (%(tenant_id)s::UUID, %(storage_type)s, %(key)s, %(name)s, %(size)s, %(extension)s, %(mime_type)s, %(created_by_role)s, %(created_by)s::UUID, %(created_at)s, %(used)s, %(used_by)s::UUID, %(used_at)s, %(hash)s, %(source_url)s) RETURNING upload_files.id] [parameters: {'tenant_id': '52cb0a76-f4da-4a1b-b4dc-a7a4b06ace5f', 'storage_type': 'local', 'key': 'upload_files/52cb0a76-f4da-4a1b-b4dc-a7a4b06ace5f/5fe9423c-5000-48cc-8e7e-5bdcade976ba.png', 'name': 'image.png', 'size': 309738, 'extension': 'png', 'mime_type': 'image/png', 'created_by_role': 'account', 'created_by': '2fa5269a-43be-4092-a82c-44e2a0e3d81b', 'created_at': datetime.datetime(2024, 12, 6, 11, 18, 42, 27112), 'used': False, 'used_by': None, 'used_at': None, 'hash': 'd17a7b6ecb08c68454d4ecbe365015144297e46a1aad314e3f526df4b906682e', 'source_url': ''}] (Background on this error at: https://sqlalche.me/e/20/f405) ``` ![image](https://github.com/user-attachments/assets/951d1519-76cf-4811-9876-786c5602ab5e)
yindo added the 🤔 cant-reproduce label 2026-02-21 18:18:53 -05:00
yindo closed this issue 2026-02-21 18:18:53 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 6, 2024):

To resolve the "UndefinedColumn" error related to the "source_url" column in the "upload_files" table, you need to ensure that the database migration adding this column has been applied. The migration script 2024_11_01_0434-d3f6769a94a3_add_upload_files_source_url.py is responsible for adding the source_url column to the upload_files table.

Here are the steps you should follow:

  1. Run the Migration: Make sure that the Alembic migration has been executed. You can do this by running the Alembic upgrade command to apply the latest migrations:

    alembic upgrade head
    

    This command will apply all pending migrations, including the one that adds the source_url column.

  2. Verify the Migration: Check the database to ensure that the source_url column exists in the upload_files table. You can do this by querying the database schema or using a database management tool.

If the migration has been applied and the column still does not exist, ensure that the database URL and Alembic configuration are correct [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Dec 6, 2024): <!-- Answer --> To resolve the "UndefinedColumn" error related to the "source_url" column in the "upload_files" table, you need to ensure that the database migration adding this column has been applied. The migration script `2024_11_01_0434-d3f6769a94a3_add_upload_files_source_url.py` is responsible for adding the `source_url` column to the `upload_files` table. Here are the steps you should follow: 1. **Run the Migration**: Make sure that the Alembic migration has been executed. You can do this by running the Alembic upgrade command to apply the latest migrations: ```bash alembic upgrade head ``` This command will apply all pending migrations, including the one that adds the `source_url` column. 2. **Verify the Migration**: Check the database to ensure that the `source_url` column exists in the `upload_files` table. You can do this by querying the database schema or using a database management tool. If the migration has been applied and the column still does not exist, ensure that the database URL and Alembic configuration are correct <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/migrations/versions/2024_11_01_0434-d3f6769a94a3_add_upload_files_source_url.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/migrations/versions/2024_11_01_0540-f4d7ce70a7ca_update_upload_files_source_url.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/21d16b03-ff94-48c3-acb9-48e0a6ca68ee?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/21d16b03-ff94-48c3-acb9-48e0a6ca68ee?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/21d16b03-ff94-48c3-acb9-48e0a6ca68ee?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/21d16b03-ff94-48c3-acb9-48e0a6ca68ee?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/21d16b03-ff94-48c3-acb9-48e0a6ca68ee?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/21d16b03-ff94-48c3-acb9-48e0a6ca68ee?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Dec 6, 2024):

This error seems that the migrations were not run successfully, so you will see some missing columns. Please follow the upgrade guide to do the upgrade.

@crazywoola commented on GitHub (Dec 6, 2024): This error seems that the migrations were not run successfully, so you will see some missing columns. Please follow the upgrade guide to do the upgrade.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7093