Skip to content

wandb_gql import fails with W&B SDK >=0.27.1 - ModuleNotFoundError #3087

Description

@TM23-sanji

Bug: wandb_gql import fails with W&B SDK >=0.27.1

Package: prime-rl
File: prime_rl/utils/monitor/wandb.py
Commit: 256809b (latest main)

Description

prime_rl/utils/monitor/wandb.py imports from wandb_gql import gql — a private, vendored module that was bundled inside the W&B Python SDK. W&B SDK v0.27.1 removed this vendored module as part of PR #11818 (routing GraphQL through wandb-core).

This means a fresh pip install prime-rl resolves to wandb>=0.27.1 and fails at import time:

$ python3 -c "from prime_rl.utils.monitor.wandb import WandbMonitor"
Traceback (most recent call last):
  ...
  File "prime_rl/utils/monitor/wandb.py", line 18, in <module>
    from wandb_gql import gql
ModuleNotFoundError: No module named 'wandb_gql'

This also breaks the orchestrator and rl entrypoints since the monitor is imported at startup:

File "/home/ubuntu/wordle/.venv/bin/orchestrator", line 10, in <module>
    sys.exit(main())
  ...
  File "prime_rl/utils/monitor/wandb.py", line 18, in <module>
    from wandb_gql import gql
ModuleNotFoundError: No module named 'wandb_gql'

Root Cause

The file uses two private/internal APIs from the wandb SDK:

  1. from wandb_gql import gqlwandb_gql was a vendored copy of the gql GraphQL library inside wandb/vendor/gql-0.2.0/wandb_gql/. W&B SDK v0.27.1 deleted it.
  2. wandb.Api().client.execute()wandb.Api().client was the gql.Client instance. The modern replacement is wandb.Api()._service_api.execute_graphql().

Both were never public API — they were internal implementation details that happened to be importable.

Fix

Replacement API: wandb.Api()._service_api.execute_graphql() accepts a raw GraphQL query string (no gql() parsing needed) and returns a plain dict — same shape as before.

Changes (3 lines in one file)

File: prime_rl/utils/monitor/wandb.py

1. Remove the import (line 18):

-from wandb_gql import gql

2. Replace gql() parsing + client.execute() with raw string + execute_graphql():

-def list_views(entity: str, project: str) -> list[tuple[str, str]]:
-    query = gql(
-        """
+def list_views(entity: str, project: str) -> list[tuple[str, str]]:
+    query = """
         query Views($entity: String!, $project: String!) {
           project(name: $project, entityName: $entity) {
             allViews(viewType: "project-view") { edges { node { name displayName } } }
           }
         }
-        """
-    )
-    res = wandb.Api().client.execute(query, variable_values={"entity": entity, "project": project})
+    """
+    res = wandb.Api()._service_api.execute_graphql(query, {"entity": entity, "project": project})

That's it. The _service_api attribute exists in wandb SDK v0.27.0+ (earlier versions had client). Since v0.27.1 is required for the vendored wandb_gql removal to be a problem, this is always available.

Verified

  • Python 3.12, wandb 0.28.1 (latest)
  • WandbMonitor imports successfully
  • list_views imports successfully
  • Full rl @ config.toml --dry-run passes
  • No dependency pins or workarounds needed

Workaround (temporary)

Until this fix lands upstream, pin wandb<0.27.1:

uv pip install "wandb<0.27.1"

Context

This is the same issue that affected wandb-workspaces (fixed in v0.4.2) and the W&B MCP server (temporarily worked around with wandb<0.27.1 cap, then resolved by upgrading wandb-workspaces).

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions