Skip to content

[Feature Flags] fetch request from context in is_feature_enabled()#6157

Merged
juliawu merged 1 commit intodatacommonsorg:masterfrom
juliawu:flask-request-context
Apr 1, 2026
Merged

[Feature Flags] fetch request from context in is_feature_enabled()#6157
juliawu merged 1 commit intodatacommonsorg:masterfrom
juliawu:flask-request-context

Conversation

@juliawu
Copy link
Copy Markdown
Contributor

@juliawu juliawu commented Mar 31, 2026

This PR updates the is_feature_enabled() server-side feature flag util to attempt to fetch the request from context if one is not explicitly provided.

This will allow us to get enable_feature= query parameter values from requests without needing to pipe in the request object through deep stacks of calls.

Note that the flask request context is for the route being called. On the client side, when making flask API calls, we would just need to ensure enable_feature= is included in the request to the flask APIs, even if the page calling the APIs already has the flag enabled. 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.

@juliawu juliawu requested review from gmechali and nick-nlb March 31, 2026 21:42
@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 server-side feature flag utility by enabling automatic request resolution from the current Flask context. This change simplifies function signatures across the codebase, removing the requirement to manually pass request objects through complex call hierarchies while maintaining support for query parameter-based feature overrides.

Highlights

  • Feature Flag Utility Update: Updated the is_feature_enabled() function to automatically retrieve the request object from the Flask request context if it is not explicitly provided.
  • Simplified API Calls: Reduced the need to pass request objects through deep call stacks by leveraging Flask's request context.
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 updates the feature flag system to automatically retrieve the Flask request from the context if it is not explicitly provided to the is_feature_enabled function. Feedback suggests moving this logic into the underlying helper functions, is_feature_override_enabled and is_feature_override_disabled, to ensure consistent behavior and API usability across all public functions that accept an optional request argument.

Comment on lines +79 to +80
if request is None and has_request_context():
request = flask_request
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logic to automatically fetch the request from the Flask context is a good improvement. However, for better consistency and API usability, this logic should ideally be moved into the helper functions is_feature_override_enabled and is_feature_override_disabled (or a shared internal helper). Since those functions are public and also take an optional request argument, updating them would ensure that the 'no-piping' benefit applies regardless of whether a developer calls the main is_feature_enabled function or the specific override helpers directly.

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.

Thanks!

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.

Thanks!

@juliawu juliawu merged commit 50acfdd into datacommonsorg:master Apr 1, 2026
13 checks passed
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