One function

get_numeric_value in optimizely/python-sdk

The author described this change as Fixed a bug with how the numeric metric getters handle non string and number values. (#77). It counts as a record because the check below fails on the code as it stood at 74c3fb44a and passes on dcef2eb8c, with nothing else changed between the two runs.

Fix saved2017-09-14
Sharing licenceApache-2.0 · LICENSE
Change size+1 0

What the code was meant to do, written into the code itself as a docstring

A smart getter of the numeric value from the event tags. Args: event_tags: A dictionary of event tags. logger: Optional logger. Returns: A float numeric metric value is returned when the provided numeric metric value is in the following format: - A string (properly formatted, e.g., no commas) - An integer - A float or double None is returned when the provided numeric metric values is in the following format: - None - A boolean - inf, -inf, nan - A string not properly formatted (e.g., '1,234') - Any values that cannot be cast to a float (e.g., an array or dictionary)

The change

5656 numeric_metric_value = cast_numeric_metric_value
5757 else:
5858 logger_message_debug = 'Numeric metric value is not in integer, float, or string form.'
59+ numeric_metric_value = None
5960
6061 except ValueError:
6162 logger_message_debug = 'Value error while casting numeric metric value to a float.'

The check that tells the two apart

failpass·tests/helpers_tests/test_event_tag_utils.py::EventTagUtilsTest::test_get_numeric_metric__value_tag

Check file tests/helpers_tests/test_event_tag_utils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it74c3fb44a26bc6415ea167fd3a13d58ec8fb90be
Broken version dated2017-09-14
Moduleoptimizely.helpers.event_tag_utils
Units changedget_numeric_value
Fingerprintfe3ac4fbf0f3bac7
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.