Skip to content

[v0/v1 migration] Have flask is_feature_flag logic fetch request from context, add flag for v2/recognize/places#6155

Closed
juliawu wants to merge 2 commits intodatacommonsorg:masterfrom
juliawu:flag-api-calls
Closed

[v0/v1 migration] Have flask is_feature_flag logic fetch request from context, add flag for v2/recognize/places#6155
juliawu wants to merge 2 commits intodatacommonsorg:masterfrom
juliawu:flag-api-calls

Conversation

@juliawu
Copy link
Copy Markdown
Contributor

@juliawu juliawu commented Mar 31, 2026

This PR:

  • Updates the is_feature_enabled() function in our flask server to fetch the request from context if available (and if an explicit request object is not provided).
  • As proof of concept, this PR also implements a flag check for switching between v1/recognize/places and v2/recognize/places.
  • Adds the use_v2_api flag to feature_flags.py to implement the above bullet point.

This will allow us to get enable_feature= query parameter values from requests without needing to pipe in the request object through very deep stacks of calls. On the client side, we would just need to ensure enable_feature= is included in the request to flask APIs. For example, even if we are on datacommons.org?enable_feature=use_v2_api, if that page makes a call to api/route, we would need to update the client side code to make a call to api/route?enable_feature=use_v2_api.

Testing:
To verify this flow, I added logging statements to dc.recognize_places() and verified that:

Uses V1 API
http://localhost:8080/explore?enable_feature=enable_stat_var_autocomplete#q=jobs%20in%20texas

Uses V2 API
http://localhost:8080/explore?enable_feature=enable_stat_var_autocomplete&enable_feature=use_v2_api#q=jobs%20in%20texas

Note that this page does not make a separate request to the flask apis, so no extra enable_feature=use_v2_api piping was needed.

@juliawu juliawu requested review from gmechali and nick-nlb March 31, 2026 20:44
@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 improves the developer experience for handling feature flags by reducing the need to manually pass request objects through deep call stacks. It also establishes a mechanism for A/B testing or gradual migration between API versions by implementing a configurable flag for the recognize places service.

Highlights

  • Context-aware feature flags: Updated the is_feature_enabled function to automatically resolve the request object from the Flask request context if not explicitly provided.
  • API Versioning: Introduced a USE_V2_API feature flag to allow toggling between v1 and v2 endpoints for place recognition.
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 introduces a USE_V2_API feature flag to toggle between V1 and V2 versions of the recognize_places endpoint, updates the feature flag utility to automatically handle Flask request contexts, and adds the V1 endpoint to the service discovery list. I have no feedback to provide.

@juliawu
Copy link
Copy Markdown
Contributor Author

juliawu commented Mar 31, 2026

Closing in favor of separate PRs, one for the v*/recognize/places, the other for the update to is_feature_enabled()

Copy link
Copy Markdown
Contributor

@gmechali gmechali left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@juliawu
Copy link
Copy Markdown
Contributor Author

juliawu commented Apr 1, 2026

Closing, these changes have been implemented in #6156 and #6159

@juliawu juliawu closed this Apr 1, 2026
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.

2 participants