- 
                Notifications
    
You must be signed in to change notification settings  - Fork 11
 
fix: omit segments from evaluation context in get_environment_flags #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: khvn26 <979078+khvn26@users.noreply.github.com>
Co-authored-by: khvn26 <979078+khvn26@users.noreply.github.com>
Co-authored-by: khvn26 <979078+khvn26@users.noreply.github.com>
        
          
                tests/test_flagsmith.py
              
                Outdated
          
        
      | flagsmith._evaluation_context = evaluation_context | ||
| flagsmith.enable_local_evaluation = True | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use local_eval_flagsmith fixture instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 10242fb
        
          
                tests/test_flagsmith.py
              
                Outdated
          
        
      | # Given | ||
| flagsmith._evaluation_context = evaluation_context | ||
| flagsmith.enable_local_evaluation = True | ||
| mock_engine = mocker.patch("flagsmith.flagsmith.engine") | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mock specific function and use autospec:
| mock_engine = mocker.patch("flagsmith.flagsmith.engine") | |
| mock_get_evaluation_result = mocker.patch( | |
| "flagsmith.flagsmith.engine.get_evaluation_result", | |
| autospec=True, | |
| ) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 10242fb
        
          
                tests/test_flagsmith.py
              
                Outdated
          
        
      | mock_engine.get_evaluation_result.assert_called_once() | ||
| call_args = mock_engine.get_evaluation_result.call_args | ||
| context = call_args[1]["context"] | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use assert_called_once_with method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 10242fb
        
          
                tests/test_flagsmith.py
              
                Outdated
          
        
      | mock_engine.get_evaluation_result.assert_called_once() | ||
| call_args = mock_engine.get_evaluation_result.call_args | ||
| context = call_args[1]["context"] # Keyword argument 'context' | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use assert_called_once_with method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 10242fb
        
          
                flagsmith/flagsmith.py
              
                Outdated
          
        
      | context_without_segments = typing.cast( | ||
| SDKEvaluationContext, | ||
| { | ||
| key: value | ||
| for key, value in self._evaluation_context.items() | ||
| if key != "segments" | ||
| }, | ||
| ) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helps to avoid both the cast and a bytecode loop:
| context_without_segments = typing.cast( | |
| SDKEvaluationContext, | |
| { | |
| key: value | |
| for key, value in self._evaluation_context.items() | |
| if key != "segments" | |
| }, | |
| ) | |
| context_without_segments = self._evaluation_context.copy() | |
| context_without_segments.pop("segments", None) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 10242fb
| 
           @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 <979078+khvn26@users.noreply.github.com>
          
 All review comments addressed in 10242fb. Changes include: 
 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:
 If you need me to access, download, or install something from one of these locations, you can either: 
  | 
    
Fix for issue #6051: Omit segments from evaluation context when
get_environment_flagsis calledThis 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:
_get_environment_flags_from_document()to filter out segments from the evaluation context before passing it to the enginecopy()andpop()instead of dictionary comprehensioncontext=...) for allengine.get_evaluation_resultcallsTesting & Quality:
Impact:
Ready for review!
Original prompt
get_environment_flagsincludes segments in evaluation context #172💡 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.