Skip to content

[v0/v1 migration] Migrate get_variable_ancestors from v1 to v2 API#6144

Merged
SandeepTuniki merged 17 commits intomasterfrom
migrate-v1-variable-ancestors-to-v2-node
Apr 3, 2026
Merged

[v0/v1 migration] Migrate get_variable_ancestors from v1 to v2 API#6144
SandeepTuniki merged 17 commits intomasterfrom
migrate-v1-variable-ancestors-to-v2-node

Conversation

@SandeepTuniki
Copy link
Copy Markdown
Contributor

@SandeepTuniki SandeepTuniki commented Mar 30, 2026

This PR migrates the website code from consuming /v1/variable/ancestors/ endpoint to v2/node api (b/459854663).

Instead of a single call to the /v1/variable/ancestors/ endpoint, we now make multiple calls to v2/node endpoint to fetch one ancestor at a time and return all of them in a single list to the frontend.

I evaluated the possibility of leveraging the v2/node endpoint's specializationOf+ feature that recursively traverses the entire hierarchy at once, but found that the endpoint returns the ancestors in an alphabetically sorted order, so the direct parent-child edge relationships within that recursive chain are lost in the response. So instead, I went with repeated calls approach and memoized it to reduce latency of repeated lookups.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the backend service to consume the v2/node API for retrieving statistical variable ancestors. By replacing the legacy v1 endpoint with a custom traversal implementation, the system gains more control over the hierarchy resolution process, including specific tie-breaking rules and cycle detection, while maintaining performance through added caching.

Highlights

  • API Migration: Migrated the get_variable_ancestors function from the deprecated /v1/variable/ancestors endpoint to the v2/node API.
  • Logic Implementation: Implemented a manual traversal of the specializationOf arc with custom tie-breaking logic and cycle detection to replace the previous endpoint functionality.
  • Caching: Added memoization to the get_variable_ancestors function to improve performance.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the get_variable_ancestors function to manually traverse the variable hierarchy using v2node calls instead of a single API endpoint. The new implementation includes caching, cycle detection, and specific tie-breaking logic for custom prefixes. Feedback suggests improving code maintainability by reusing the _get_all_values helper and simplifying the tie-breaking logic using a generator expression.

Comment thread server/services/datacommons.py Outdated
Comment thread server/services/datacommons.py Outdated
@SandeepTuniki SandeepTuniki marked this pull request as ready for review March 30, 2026 15:03
@SandeepTuniki SandeepTuniki requested a review from juliawu March 30, 2026 15:03
Comment thread server/services/datacommons.py Outdated
@SandeepTuniki
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the direct call to the /v1/variable/ancestors endpoint with a manual traversal of the variable hierarchy using memberOf and specializationOf relationships, incorporating caching and cycle detection. The reviewer noted that the use of asyncio.run within a loop is inefficient and recommended simplifying the logic by removing the asynchronous overhead and utilizing existing helper functions for response parsing.

Comment thread server/services/datacommons.py Outdated
@SandeepTuniki SandeepTuniki requested a review from juliawu March 31, 2026 09:43
juliawu
juliawu previously approved these changes Mar 31, 2026
Copy link
Copy Markdown
Contributor

@juliawu juliawu left a comment

Choose a reason for hiding this comment

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

Nice! Just left a suggestion to consider.

Comment thread server/services/datacommons.py
@juliawu juliawu dismissed their stale review March 31, 2026 17:42

Witholding approval temporarily until we get feature flags set up, just so this PR does not get merged in the meantime.

@nick-nlb nick-nlb changed the title Migrate get_variable_ancestors from v1 to v2 API [v0/v1 migration] Migrate get_variable_ancestors from v1 to v2 API Mar 31, 2026
@juliawu juliawu requested a review from nick-nlb April 1, 2026 21:22
Copy link
Copy Markdown
Contributor

@nick-nlb nick-nlb left a comment

Choose a reason for hiding this comment

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

I haven't yet done a full run through but a quick initial review before we meet!

Comment thread server/services/discovery.py
Copy link
Copy Markdown
Contributor

@nick-nlb nick-nlb left a comment

Choose a reason for hiding this comment

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

Added in one comment (not a major one) - the most important one is from the previous review batch (about the missing endpoint for v1 in discovery). Some of the test failures may relate to that, as environments that don't use v2 wouldn't be able to use the old fallback endpoint.

Comment thread static/js/utils/url_utils.ts Outdated
@nick-nlb nick-nlb self-requested a review April 3, 2026 01:07
Copy link
Copy Markdown
Contributor

@nick-nlb nick-nlb left a comment

Choose a reason for hiding this comment

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

Thank you Sandeep and Julia! LGTM

@SandeepTuniki Just a note that this PR was requested as a merge from a branch directly in upstream (the primary DC repo), instead of from your own fork.

@SandeepTuniki
Copy link
Copy Markdown
Contributor Author

Thanks, Julia & NIck. Merging this PR.

@SandeepTuniki SandeepTuniki merged commit b1c1436 into master Apr 3, 2026
13 checks passed
@SandeepTuniki SandeepTuniki deleted the migrate-v1-variable-ancestors-to-v2-node branch April 3, 2026 03:13
@SandeepTuniki
Copy link
Copy Markdown
Contributor Author

@SandeepTuniki Just a note that this PR was requested as a merge from a branch directly in upstream (the primary DC repo), instead of from your own fork.

@nick-nlb Yes, I usually just create a branch in the repo instead of a fork, to keep the development flow straightforward. Is there a different convention we follow for this repo?

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.

3 participants