Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Fix for issue #6051: Omit segments from evaluation context when get_environment_flags is called

This change addresses the issue where segments were unnecessarily included in the evaluation context when retrieving environment flags. Segments are only relevant for identity-specific evaluations, not for environment-wide flag evaluations.

Changes made:

  • Modified _get_environment_flags_from_document() to filter out segments from the evaluation context before passing it to the engine
  • Simplified implementation using copy() and pop() instead of dictionary comprehension
  • Uses consistent keyword argument style (context=...) for all engine.get_evaluation_result calls
  • Added comprehensive tests with proper fixtures and mocking

Testing & Quality:

  • ✅ All existing tests pass (73 tests)
  • ✅ All linters pass (black, isort, flake8, mypy)
  • ✅ Code review feedback addressed

Impact:

  • Improves performance by reducing unnecessary data in the evaluation context for environment flags
  • Maintains backward compatibility - no API changes
  • Segments continue to work correctly for identity-specific evaluations

Ready for review!

Original prompt

This section details on the original issue you should resolve

<issue_title>get_environment_flags includes segments in evaluation context</issue_title>
<issue_description>See Flagsmith/flagsmith#6051.

In the mapper layer, omit segments from evaluation context when get_environment_flags is called.</issue_description>

<agent_instructions>use conventional-commit for PR title:
fix:

add a new test — perhaps by adding test_mappers.py

verify with pytest and pre-commit run -a</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix get_environment_flags to omit segments in evaluation context fix: omit segments from evaluation context in get_environment_flags Oct 31, 2025
Copilot AI requested a review from khvn26 October 31, 2025 19:57
Copilot finished work on behalf of khvn26 October 31, 2025 19:57
@khvn26
Copy link
Member

khvn26 commented Oct 31, 2025

@copilot Please address the review comments above.

- Use local_eval_flagsmith fixture in tests
- Mock specific function with autospec
- Use assert_called_once_with for cleaner assertions
- Simplify context filtering with copy() and pop()

Co-authored-by: khvn26 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot Please address the review comments above.

All review comments addressed in 10242fb. Changes include:

  • Using local_eval_flagsmith fixture
  • Mocking specific function with autospec=True
  • Using assert_called_once_with for cleaner assertions
  • Simplified context filtering with copy() and pop()

All tests pass (73/73) and linters are clean.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • test_urlanalytics
    • Triggering command: /home/REDACTED/.cache/pypoetry/virtualenvs/flagsmith-K6knkhUn-py3.12/bin/python /home/REDACTED/.cache/pypoetry/virtualenvs/flagsmith-K6knkhUn-py3.12/bin/pytest tests/ -x (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from khvn26 October 31, 2025 22:32
Copilot finished work on behalf of khvn26 October 31, 2025 22:32
Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

Yup, LGTM.

@khvn26 khvn26 changed the title fix: omit segments from evaluation context in get_environment_flags fix: get_environment_flags includes segments in evaluation context Nov 12, 2025
@khvn26 khvn26 marked this pull request as ready for review November 12, 2025 16:52
@khvn26 khvn26 requested a review from a team as a code owner November 12, 2025 16:52
@khvn26 khvn26 requested review from Zaimwa9 and removed request for a team November 12, 2025 16:52
Copy link
Contributor

@emyller emyller left a comment

Choose a reason for hiding this comment

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

This was easier to comprehend by reading the code, than from the overly verbose and situation-contextualized PR description. 😞

Changes LGTM

@khvn26 khvn26 merged commit 470c4e3 into main Nov 12, 2025
13 checks passed
@khvn26 khvn26 deleted the copilot/fix-get-environment-flags-issue branch November 12, 2025 17:28
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.

get_environment_flags includes segments in evaluation context

3 participants