about "refactor: extract cors configs into dify config and cleanup the confi… …g class (#5507)" #4262

Closed
opened 2026-02-21 18:05:27 -05:00 by yindo · 6 comments
Owner

Originally created by @hymvp on GitHub (Jun 25, 2024).

Originally assigned to: @bowenliang123, @laipz8200 on GitHub.

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).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Cloud

Steps to reproduce

After my testing, deleting config.py may cause custom file storage errors (/api/extensions/storage)
docker compose logs -f api
api-1 | return self._emit(event_name, kwargs)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/botocore/hooks.py", line 239, in _emit
api-1 | response = handler(**kwargs)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/botocore/handlers.py", line 278, in validate_bucket_name
api-1 | if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket):
api-1 | TypeError: expected string or bytes-like object

✔️ Expected Behavior

Upload files to s3 bucket

Actual Behavior

After my testing, deleting config.py may cause custom file storage errors (/api/extensions/storage)
api-1 | return self._emit(event_name, kwargs)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/botocore/hooks.py", line 239, in _emit
api-1 | response = handler(**kwargs)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/botocore/handlers.py", line 278, in validate_bucket_name
api-1 | if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket):
api-1 | TypeError: expected string or bytes-like object

Originally created by @hymvp on GitHub (Jun 25, 2024). Originally assigned to: @bowenliang123, @laipz8200 on GitHub. ### 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] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.11 ### Cloud or Self Hosted Cloud ### Steps to reproduce After my testing, deleting config.py may cause custom file storage errors (/api/extensions/storage) docker compose logs -f api api-1 | return self._emit(event_name, kwargs) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/botocore/hooks.py", line 239, in _emit api-1 | response = handler(**kwargs) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/botocore/handlers.py", line 278, in validate_bucket_name api-1 | if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket): api-1 | TypeError: expected string or bytes-like object ### ✔️ Expected Behavior Upload files to s3 bucket ### ❌ Actual Behavior After my testing, deleting config.py may cause custom file storage errors (/api/extensions/storage) api-1 | return self._emit(event_name, kwargs) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/botocore/hooks.py", line 239, in _emit api-1 | response = handler(**kwargs) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/botocore/handlers.py", line 278, in validate_bucket_name api-1 | if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket): api-1 | TypeError: expected string or bytes-like object
yindo added the 🐞 bug label 2026-02-21 18:05:27 -05:00
yindo closed this issue 2026-02-21 18:05:27 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 25, 2024):

Hey @hymvp! I'm here to help you with your bug report. I can assist with bug fixes, answer questions, and guide you on becoming a contributor. Let's tackle this together while we wait for a human maintainer.

Ensure that the S3_BUCKET_NAME configuration is correctly set in your application configuration. The S3Storage class relies on this configuration, and if it is missing or incorrect, it can lead to errors during bucket name validation.

In your configuration file (which might be config.py or another configuration source), you should have:

S3_BUCKET_NAME = 'your-bucket-name'
S3_SECRET_KEY = 'your-secret-key'
S3_ACCESS_KEY = 'your-access-key'
S3_ENDPOINT = 'your-endpoint-url'
S3_REGION = 'your-region'
S3_ADDRESS_STYLE = 'your-addressing-style'

Replace 'your-bucket-name', 'your-secret-key', 'your-access-key', 'your-endpoint-url', 'your-region', and 'your-addressing-style' with the actual values for your S3 setup.

Additionally, ensure that the STORAGE_TYPE in your application configuration is set to 's3':

STORAGE_TYPE = 's3'

This will ensure that the S3Storage class is properly initialized and used for file storage operations [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 25, 2024): <!-- Greeting --> Hey @hymvp! I'm here to help you with your bug report. I can assist with bug fixes, answer questions, and guide you on becoming a contributor. Let's tackle this together while we wait for a human maintainer. <!-- Answer --> Ensure that the `S3_BUCKET_NAME` configuration is correctly set in your application configuration. The `S3Storage` class relies on this configuration, and if it is missing or incorrect, it can lead to errors during bucket name validation. In your configuration file (which might be `config.py` or another configuration source), you should have: ```python S3_BUCKET_NAME = 'your-bucket-name' S3_SECRET_KEY = 'your-secret-key' S3_ACCESS_KEY = 'your-access-key' S3_ENDPOINT = 'your-endpoint-url' S3_REGION = 'your-region' S3_ADDRESS_STYLE = 'your-addressing-style' ``` Replace `'your-bucket-name'`, `'your-secret-key'`, `'your-access-key'`, `'your-endpoint-url'`, `'your-region'`, and `'your-addressing-style'` with the actual values for your S3 setup. Additionally, ensure that the `STORAGE_TYPE` in your application configuration is set to `'s3'`: ```python STORAGE_TYPE = 's3' ``` This will ensure that the `S3Storage` class is properly initialized and used for file storage operations <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/extensions/storage/s3_storage.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/extensions/ext_storage.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Jun 25, 2024):

Link #5507 @bowenliang123 Could you take a look at this?

@crazywoola commented on GitHub (Jun 25, 2024): Link #5507 @bowenliang123 Could you take a look at this?
Author
Owner

@bowenliang123 commented on GitHub (Jun 25, 2024):

Hi @hymvp , could you have a try with #5590 manually in your code to see whether the problem still occurs?

@bowenliang123 commented on GitHub (Jun 25, 2024): Hi @hymvp , could you have a try with #5590 manually in your code to see whether the problem still occurs?
Author
Owner

@bowenliang123 commented on GitHub (Jun 25, 2024):

also cc @takatost

@bowenliang123 commented on GitHub (Jun 25, 2024): also cc @takatost
Author
Owner

@hymvp commented on GitHub (Jun 25, 2024):

hi @bowenliang123, i refer to https://github.com/langgenius/dify/pull/5590 modify app.py ,the problem still occurs

@hymvp commented on GitHub (Jun 25, 2024): hi @bowenliang123, i refer to https://github.com/langgenius/dify/pull/5590 modify app.py ,the problem still occurs
Author
Owner

@bowenliang123 commented on GitHub (Jun 25, 2024):

Then, #5590 is not relevant in your case. The configs for storage seems read from Flask app config not directly from the env vars.

Could you @hymvp

  1. debug to see the bucket value where the exception thrown at "botocore/hooks.py" L278
  2. attach full messages and traceback of the exception
  3. show us the way you set the configs, eg. in .env file for via system enrionments, and the exact values
    ?
@bowenliang123 commented on GitHub (Jun 25, 2024): Then, #5590 is not relevant in your case. The configs for storage seems read from Flask app config not directly from the env vars. Could you @hymvp 1. debug to see the `bucket` value where the exception thrown at "botocore/hooks.py" L278 2. attach full messages and traceback of the exception 3. show us the way you set the configs, eg. in .env file for via system enrionments, and the exact values ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4262