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
43.12k stars 5.98k forks source link

Notion integration results in error vars() argument must have __dict__ attribute #6150

Closed mikelmao closed 3 weeks ago

mikelmao commented 1 month ago

Self Checks

Dify version

0.6.13

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Install a self hosted version of Dify
  2. Configure environment variables NOTION_INTEGRATION_TYPE set to "internal" and set NOTION_INTERNAL_SECRET as the secret provided from the Notion integration
  3. Go to the Dify dashboard -> settings -> Datasources
  4. Click "+ add workspace" for the notion integration
  5. Server error pops up
  6. View the logs
  7. Find error: "vars() argument must have dict attribute"

Results in

TypeError

console.oauthdatasource

Sentry shows the following lines of code:

        if not current_user.is_admin_or_owner:
            raise Forbidden()
        OAUTH_DATASOURCE_PROVIDERS = get_oauth_providers()
        with current_app.app_context():
            oauth_provider = OAUTH_DATASOURCE_PROVIDERS.get(provider)
            print(vars(oauth_provider))
        if not oauth_provider:
            return {'error': 'Invalid provider'}, 400
        if dify_config.NOTION_INTEGRATION_TYPE == 'internal':
            internal_secret = dify_config.NOTION_INTERNAL_SECRET
            if not internal_secret:

Specifically erroring out on

print(vars(oauth_provider))

✔️ Expected Behavior

Continuing with the ability to hook up a workspace

❌ Actual Behavior

Error: "vars() argument must have dict attribute"

dosubot[bot] commented 1 month ago

The error "vars() argument must have __dict__ attribute" indicates that the oauth_provider object does not have a __dict__ attribute, which is typically present in instances of classes that use the default __init__ method to store attributes.

In the Dify codebase, the oauth_provider object is an instance of the NotionOAuth class. This class should have attributes like client_id, client_secret, and redirect_uri [1].

To resolve this issue, you can modify the NotionOAuth class to ensure it has a __dict__ attribute. One way to do this is to define the __slots__ attribute in the class, which explicitly declares data members and prevents the creation of a __dict__ attribute. If __slots__ is used, you can remove it to allow the creation of a __dict__ attribute.

Here's an example of how you might modify the NotionOAuth class:

class NotionOAuth:
    def __init__(self, client_id, client_secret, redirect_uri):
        self.client_id = client_id
        self.client_secret = client_secret
        self.redirect_uri = redirect_uri
        # Add other necessary attributes here

If __slots__ is defined in the class, remove it:

class NotionOAuth:
    __slots__ = ['client_id', 'client_secret', 'redirect_uri']  # Remove this line if it exists
    def __init__(self, client_id, client_secret, redirect_uri):
        self.client_id = client_id
        self.client_secret = client_secret
        self.redirect_uri = redirect_uri
        # Add other necessary attributes here

After making this change, the vars(oauth_provider) call should work as expected, allowing you to proceed with the Notion integration.

If the NotionOAuth class is already defined without __slots__ and the issue persists, ensure that the oauth_provider object is correctly instantiated and not None or an unexpected type.

To continue talking to Dosu, mention @dosu.

mikelmao commented 1 month ago

As additional information @dosu it states in the docs that if you use internal as the notion integration type, it does not require the other fields other than the secret.

dosubot[bot] commented 1 month ago

The error "vars() argument must have __dict__ attribute" occurs because the oauth_provider object does not have a __dict__ attribute. This is typically present in instances of classes that use the default __init__ method to store attributes.

In the Dify codebase, the oauth_provider object is an instance of the NotionOAuth class. This class should have attributes like client_id, client_secret, and redirect_uri [1].

Given that the NOTION_INTEGRATION_TYPE is set to "internal" and only the NOTION_INTERNAL_SECRET is required, ensure that the NotionOAuth class is correctly instantiated and has the necessary attributes.

Here's an example of how you might modify the NotionOAuth class to ensure it has a __dict__ attribute:

class NotionOAuth:
    def __init__(self, client_id=None, client_secret=None, redirect_uri=None):
        self.client_id = client_id
        self.client_secret = client_secret
        self.redirect_uri = redirect_uri
        # Add other necessary attributes here

If __slots__ is defined in the class, remove it:

class NotionOAuth:
    __slots__ = ['client_id', 'client_secret', 'redirect_uri']  # Remove this line if it exists
    def __init__(self, client_id=None, client_secret=None, redirect_uri=None):
        self.client_id = client_id
        self.client_secret = client_secret
        self.redirect_uri = redirect_uri
        # Add other necessary attributes here

After making this change, the vars(oauth_provider) call should work as expected, allowing you to proceed with the Notion integration.

Additionally, ensure that the oauth_provider object is correctly instantiated and not None or an unexpected type. This should resolve the issue and allow you to continue with the Notion integration.

To continue talking to Dosu, mention @dosu.

Sanfrencon commented 1 month ago

Line 39: oauth_provider = OAUTH_DATASOURCE_PROVIDERS.get(provider) Return Nonetype cause the Vars() cannot work properly

trancuong81 commented 1 month ago

https://github.com/langgenius/dify/issues/6478#issuecomment-2251973131