-
Notifications
You must be signed in to change notification settings - Fork 362
fix(rc): evaluate custom signals whose value is falsy, fix default types #990
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
Open
Shubham-Padkonde
wants to merge
2
commits into
firebase:main
Choose a base branch
from
Shubham-Padkonde:fix/remote-config-custom-signal-defaults
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -820,6 +820,83 @@ def test_evaluate_custom_signal_semantic_version(self, | |
| assert server_config.get_boolean('is_enabled') == parameter_value | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'custom_signal_operator, target_custom_signal_value, context_value, parameter_value', | ||
| [ | ||
| (CustomSignalOperator.NUMERIC_EQUAL.value, ['0'], 0, True), | ||
| (CustomSignalOperator.NUMERIC_LESS_THAN.value, ['1'], 0, True), | ||
| (CustomSignalOperator.NUMERIC_GREATER_THAN.value, ['-1'], 0.0, True), | ||
| (CustomSignalOperator.NUMERIC_GREATER_THAN.value, ['0'], 0, False), | ||
| (CustomSignalOperator.STRING_EXACTLY_MATCHES.value, ['0'], 0, True), | ||
| ]) | ||
| def test_evaluate_custom_signal_zero_value(self, | ||
| custom_signal_operator, | ||
| target_custom_signal_value, | ||
| context_value, | ||
| parameter_value): | ||
| server_template = self._custom_signal_template(custom_signal_operator, | ||
| target_custom_signal_value) | ||
| context = {'randomization_id': '123', 'signal_key': context_value} | ||
| server_config = server_template.evaluate(context) | ||
| assert server_config.get_boolean('is_enabled') == parameter_value | ||
|
|
||
| @pytest.mark.parametrize('context_value', [[], {}]) | ||
| @pytest.mark.parametrize('operator', [ | ||
| CustomSignalOperator.NUMERIC_LESS_THAN, | ||
| CustomSignalOperator.NUMERIC_LESS_EQUAL, | ||
| CustomSignalOperator.NUMERIC_EQUAL, | ||
| CustomSignalOperator.NUMERIC_NOT_EQUAL, | ||
| CustomSignalOperator.NUMERIC_GREATER_THAN, | ||
| CustomSignalOperator.NUMERIC_GREATER_EQUAL, | ||
| ]) | ||
| def test_evaluate_custom_signal_non_numeric_value(self, context_value, operator): | ||
| server_template = self._custom_signal_template(operator.value, ['0']) | ||
| server_config = server_template.evaluate({'signal_key': context_value}) | ||
| assert server_config.get_boolean('is_enabled') is False | ||
|
|
||
| def test_evaluate_custom_signal_missing_value(self): | ||
| server_template = self._custom_signal_template( | ||
| CustomSignalOperator.NUMERIC_LESS_THAN.value, ['1']) | ||
| server_config = server_template.evaluate({'randomization_id': '123'}) | ||
| assert server_config.get_boolean('is_enabled') is False | ||
|
Comment on lines
+857
to
+861
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| def _custom_signal_template(self, custom_signal_operator, target_custom_signal_value): | ||
| condition = { | ||
| 'name': 'is_true', | ||
| 'condition': { | ||
| 'orCondition': { | ||
| 'conditions': [{ | ||
| 'andCondition': { | ||
| 'conditions': [{ | ||
| 'customSignal': { | ||
| 'customSignalOperator': custom_signal_operator, | ||
| 'customSignalKey': 'signal_key', | ||
| 'targetCustomSignalValues': target_custom_signal_value | ||
| } | ||
| }], | ||
| } | ||
| }] | ||
| } | ||
| } | ||
| } | ||
| template_data = { | ||
| 'conditions': [condition], | ||
| 'parameters': { | ||
| 'is_enabled': { | ||
| 'defaultValue': {'value': 'false'}, | ||
| 'conditionalValues': {'is_true': {'value': 'true'}} | ||
| }, | ||
| }, | ||
| 'parameterGroups': '', | ||
| 'version': '', | ||
| 'etag': '123' | ||
| } | ||
| return remote_config.init_server_template( | ||
| app=firebase_admin.get_app(), | ||
| default_config={'dog_is_cute': True}, | ||
| template_data_json=json.dumps(template_data) | ||
| ) | ||
|
|
||
| class MockAdapter(testutils.MockAdapter): | ||
| """A Mock HTTP Adapter that provides Firebase Remote Config responses with ETag in header.""" | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
With the change to allow falsy values (such as empty lists
[]or empty dictionaries{}) to pass through theNonecheck, these values can now reach_compare_numberswhen a numeric operator is evaluated.In
_compare_numbers,float(actual_value)is called. Ifactual_valueis a list or dictionary,float()raises aTypeError(e.g.,TypeError: float() argument must be a string or a real number, not 'list'). Since_compare_numbersonly catchesValueError, this will cause an unhandled exception and crash the evaluation.To prevent this,
_compare_numbersshould be updated to catch bothValueErrorandTypeError: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.
Fixed in 348de76: numeric comparisons now reject both ValueError and TypeError. Added empty-list and empty-dictionary cases for all six numeric operators: all 12 failed before the fix and now pass; the full Remote Config module passes all 47 tests. Source/test pylint and git diff --check pass. Prepared with Codex assistance.