infiniflow/ragflow · error · ConnectorMissingCredentialError

Moodle client not initialized

Error message

Moodle client not initialized

What it means

A ConnectorMissingCredentialError raised at the start of validate_connector_settings when self.moodle_client is None, i.e. load_credentials was never called or failed before the client was assigned. Validation cannot proceed because it needs the live client to call get_site_info.

Source

Thrown at common/data_source/moodle_connector.py:85

        for batch in batch_generator(generator, self.batch_size):
            yield batch

    def load_credentials(self, credentials: dict[str, Any]) -> None:
        token = credentials.get("moodle_token")
        if not token:
            raise ConnectorMissingCredentialError("Moodle API token is required")

        try:
            self.moodle_client = MoodleClient(self.moodle_url + "/webservice/rest/server.php", token)
            self.moodle_client.core.webservice.get_site_info()
        except MoodleException as e:
            if "invalidtoken" in str(e).lower():
                raise CredentialExpiredError("Moodle token is invalid or expired")
            raise ConnectorMissingCredentialError(f"Failed to initialize Moodle client: {e}")

    def validate_connector_settings(self) -> None:
        if not self.moodle_client:
            raise ConnectorMissingCredentialError("Moodle client not initialized")

        try:
            site_info = self.moodle_client.core.webservice.get_site_info()
            if not site_info.sitename:
                raise InsufficientPermissionsError("Invalid Moodle API response")
        except MoodleException as e:
            msg = str(e).lower()
            if "invalidtoken" in msg:
                raise CredentialExpiredError("Moodle token is invalid or expired")
            if "accessexception" in msg:
                raise InsufficientPermissionsError("Insufficient permissions. Ensure web services are enabled and permissions are correct.")
            raise ConnectorValidationError(f"Moodle validation error: {e}")
        except Exception as e:
            raise ConnectorValidationError(f"Unexpected validation error: {e}")

    # -------------------------------------------------------------------------
    # Data loading & polling
    # -------------------------------------------------------------------------

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Call load_credentials(credentials) successfully before validate_connector_settings().
  2. If load_credentials raised CredentialExpiredError/ConnectorMissingCredentialError, fix the token first — validation will keep failing until then.
  3. Order operations: construct -> load_credentials -> validate_connector_settings.

Example fix

# before
connector = MoodleConnector(...)
connector.validate_connector_settings()  # raises ConnectorMissingCredentialError('Moodle client not initialized')

# after
connector = MoodleConnector(...)
connector.load_credentials({'moodle_token': token})
connector.validate_connector_settings()
Defensive patterns

Strategy: validation

Validate before calling

if not getattr(connector, "moodle_client", None):
    connector.load_credentials(credentials)  # validation needs a live client

Type guard

def moodle_ready(conn) -> bool:
    return getattr(conn, "moodle_client", None) is not None

Prevention

When it happens

Trigger: Calling validate_connector_settings() on a freshly constructed MoodleConnector, or after a load_credentials attempt that raised (e.g. invalid token) leaving moodle_client unset.

Common situations: Validation-first orchestration that assumes the connector self-initializes; retry logic that calls validate after a failed load; unit tests instantiating the connector directly.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/1ecf2087b8cca531. Report an issue: GitHub.