langgenius/dify · error · ValueError

remote configs is not dict, but {type(self.remote_configs)}

Error message

remote configs is not dict, but {type(self.remote_configs)}

What it means

Raised by ApolloSettingsSource.get_field_value when self.remote_configs (populated from ApolloClient.get_all_dicts) is not a dict. This indicates the Apollo server returned an unexpected payload shape (e.g. a list, None, or an error body) rather than a per-namespace config mapping.

Source

Thrown at api/configs/remote_settings_sources/apollo/__init__.py:54

    )


class ApolloSettingsSource(RemoteSettingsSource):
    def __init__(self, configs: Mapping[str, Any]):
        self.client = ApolloClient(
            app_id=configs["APOLLO_APP_ID"],
            cluster=configs["APOLLO_CLUSTER"],
            config_url=configs["APOLLO_CONFIG_URL"],
            start_hot_update=False,
            _notification_map={configs["APOLLO_NAMESPACE"]: -1},
        )
        self.namespace = configs["APOLLO_NAMESPACE"]
        self.remote_configs = self.client.get_all_dicts(self.namespace)

    @override
    def get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str, bool]:
        if not isinstance(self.remote_configs, dict):
            raise ValueError(f"remote configs is not dict, but {type(self.remote_configs)}")
        field_value = self.remote_configs.get(field_name)
        return field_value, field_name, False

View on GitHub (pinned to ef8544b173)

Solutions

  1. Verify APOLLO_APP_ID, APOLLO_CLUSTER, APOLLO_CONFIG_URL, and APOLLO_NAMESPACE match the Apollo project.
  2. Hit APOLLO_CONFIG_URL directly and confirm the namespace returns a JSON object.
  3. Check Apollo server logs / network for non-200 or transformed payloads.
  4. Ensure no proxy is stripping or re-wrapping the response body.

Example fix

// before
APOLLO_NAMESPACE=wrong-namespace
// after
APOLLO_NAMESPACE=dify-application
// (confirm GET {APOLLO_CONFIG_URL}/configs/{app_id}/{cluster}/{namespace} returns a JSON object)
Defensive patterns

Strategy: try-catch

Validate before calling

from urllib.request import urlopen
import json

def apollo_namespace_is_dict(config_url: str, app_id: str, cluster: str, namespace: str) -> bool:
    url = f'{config_url.rstrip("/")}/configs/{app_id}/{cluster}/{namespace}'
    with urlopen(url, timeout=5) as r:
        body = json.loads(r.read().decode())
    return isinstance(body, dict) and isinstance(body.get('configurations', {}), dict)

Type guard

def is_config_dict(value) -> bool:
    return isinstance(value, dict)

Try / catch

try:
    source = ApolloSettingsSource(configs)
except (ValueError, RuntimeError):
    logger.exception('Apollo remote config unavailable; falling back to local settings')
    source = None

Prevention

When it happens

Trigger: Apollo namespace misconfigured, Apollo server returns an error JSON or non-dict object, or get_all_dicts returns None due to a transport/parse issue internal to the client.

Common situations: Wrong APOLLO_NAMESPACE, Apollo cluster mismatch, network proxy rewriting the response, or an Apollo version that returns a different schema.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/472a71e4d2726337. Report an issue: GitHub.