One function

DecimalEncoder in Flagsmith/flagsmith-engine

The author described this change as Fix json decimal encoder (#54). It counts as a record because the check below fails on the code as it stood at 8710c94f2 and passes on 43a06d3f4, with nothing else changed between the two runs.

Fix saved2021-12-01
Sharing licenceBSD-3-Clause · LICENSE.txt
Change size+1 1

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

Convert decimal to int/float because decimals are nothing but int/float(for us) converted to decimal by boto3/dynamodb.

The change

66
77 def default(self, obj):
88 if isinstance(obj, decimal.Decimal):
9- if obj % 1 == 1:
9+ if obj % 1 == 0:
1010 return int(obj)
1111 return float(obj)
1212 return json.JSONEncoder.default(self, obj)

The check that tells the two apart

failpass·tests/unit/utils/json/test_encoders.py::test_decimal_encoder_converts_decimal

Check file tests/unit/utils/json/test_encoders.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 it8710c94f21bf5b264c7024e89109f96cae744e92
Broken version dated2021-11-30
Moduleflag_engine.utils.json.encoders
Units changedDecimalEncoder
Fingerprinta900de2ef15933fc
Checked2026-08-18 by goldset/0.1

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

Other bugs found in Flagsmith/flagsmith-engine