Skip to content

Commit 1b78a33

Browse files
committed
Exclude decimal.Decimal from built-in BSON checks
1 parent b24288e commit 1b78a33

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

bson/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,8 @@ def _encode_maxkey(name: bytes, dummy0: Any, dummy1: Any, dummy2: Any) -> bytes:
920920
if hasattr(_typ, "_type_marker"):
921921
_MARKERS[_typ._type_marker] = _ENCODERS[_typ]
922922

923-
924-
_BUILT_IN_TYPES = tuple(t for t in _ENCODERS)
923+
# Exclude decimal.Decimal since auto-conversion is explicitly opt-in.
924+
_BUILT_IN_TYPES = tuple(t for t in _ENCODERS if t != decimal.Decimal)
925925

926926

927927
def _name_value_to_bson(

test/test_bson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ def test_codec_options_repr(self):
12371237
"unicode_decode_error_handler='strict', "
12381238
"tzinfo=None, type_registry=TypeRegistry(type_codecs=[], "
12391239
"fallback_encoder=None), "
1240-
"datetime_conversion=DatetimeConversion.DATETIME)"
1240+
"datetime_conversion=DatetimeConversion.DATETIME, convert_decimal=False)"
12411241
)
12421242
self.assertEqual(r, repr(CodecOptions()))
12431243

0 commit comments

Comments
 (0)