Skip to content

Conversation

@tonyyli-wandb
Copy link
Contributor

@tonyyli-wandb tonyyli-wandb commented Nov 26, 2025

Description

Ensure the GraphQL operation called by Api.registries() uses the new Organization.registries field when available + applicable.

For now, we still have to fall back on the prior query (i.e. selecting Organization.orgEntity.projects(...)) when:

  • the server version is older and does not support Organization.registries
  • the query args include non-null filters on registry projects. Note that Organization.registries(...) does not yet accept a filters: JSONString arg.

Testing

How was this PR tested?

@tonyyli-wandb tonyyli-wandb requested review from a team as code owners November 26, 2025 21:23
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 93.18182% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
wandb/apis/public/registries/registries_search.py 80.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tonyyli-wandb tonyyli-wandb force-pushed the tonyyli/fix-registries-query-registries-directly-by-organization-when-possible branch from f34cb8a to af4d7dd Compare November 26, 2025 21:52
Copy link
Contributor

@pingleiwandb pingleiwandb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just nit and my python noob questions (as usual 🐶 )

if server_supports(client, pb.REGISTRIES_ON_ORGANIZATION) and (not filter):
self.QUERY = gql(gen.FETCH_REGISTRIES_GQL)
self._result_cls = gen.FetchRegistries
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why the the legacy branch is the one not covered by tests? I would assume existing tests on (not released) server image would trigger the old branch because server_supports would return false and fall into this branch.

Or the coverage is from mocks?...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing it's at least partly due to the failing tests, which wouldn't count toward test coverage IIRC. Though TBD (need to take a closer look and fix the tests either way once I get a chance)

TOTAL_COUNT_IN_FILE_CONNECTION = 15;

// Indicates that the server supports querying for registries on an organization.
REGISTRIES_ON_ORGANIZATION = 16;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, we define sever feature flag on server without proto, how did it endup being proto on SDK side?

Copy link
Contributor Author

@tonyyli-wandb tonyyli-wandb Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've noticed this too but it's probably better if I defer to the SDK team for more context on the original implementation

(If I had to guess, it might have been needed for compatibility with sdk-core, but treat this as pure speculation that could be wrong)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not ((org := result.organization) and (org_entity := org.org_entity)):
result = self._result_cls.model_validate(data)

# FIXME: Tighten this up a bit, this results in `conn` being unbound in the `try` block below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we just add a final else to throw some internal error because conn is not set when we server return some invalid response?

btw: (not related to the feature itself), is there a way in python (library) to make the chain of check easier? Similar to js's optional chaining? org?.org_entity?.projects

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw: (not related to the feature itself), is there a way in python (library) to make the chain of check easier? Similar to js's optional chaining? org?.org_entity?.projects

Not really AFAIK but it's a good question and I want something like this so much (so does a lot of the Python community, I'm sure).

The closest I've seen is the returns library, which defines a Maybe container (along with Some/Nothing types) that may look familiar from other languages.

Main downsides of using it here --

  • it's a whole extra added dependency
  • it's still kind of verbose
  • if you're not already familiar with it, it requires extra learning to get familiar with how -- and how not -- to use it. (pydantic has this tradeoff too ofc, but I think pydantic has much more immediate benefits)
  • It doesn't always play well with Python type hints / type checks. Not really the library's fault, they've actually done a lot to make sure the library is as fully typed as possible (there are just inevitable corner cases that Python's typing still can't express/handle well for now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants