langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
35.59k stars 4.8k forks source link

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

Open hymvp opened 4 days ago

hymvp commented 4 days ago

Self Checks

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

dosubot[bot] commented 4 days ago

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.

crazywoola commented 4 days ago

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

bowenliang123 commented 4 days ago

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

bowenliang123 commented 4 days ago

also cc @takatost

hymvp commented 3 days ago

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

bowenliang123 commented 3 days ago

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 ?