Skip to content

Commit 838a8ac

Browse files
authored
Merge branch 'mongodb:master' into arm64-runner
2 parents 8aa2222 + 0d4c84e commit 838a8ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3637
-688
lines changed

.evergreen/remove-unimplemented-tests.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ PYMONGO=$(dirname "$(cd "$(dirname "$0")" || exit; pwd)")
33

44
rm $PYMONGO/test/transactions/legacy/errors-client.json # PYTHON-1894
55
rm $PYMONGO/test/connection_monitoring/wait-queue-fairness.json # PYTHON-1873
6-
rm $PYMONGO/test/client-side-encryption/spec/unified/fle2v2-BypassQueryAnalysis.json # PYTHON-5143
7-
rm $PYMONGO/test/client-side-encryption/spec/unified/fle2v2-EncryptedFields-vs-EncryptedFieldsMap.json # PYTHON-5143
8-
rm $PYMONGO/test/client-side-encryption/spec/unified/localSchema.json # PYTHON-5143
9-
rm $PYMONGO/test/client-side-encryption/spec/unified/maxWireVersion.json # PYTHON-5143
10-
rm $PYMONGO/test/unified-test-format/valid-pass/poc-queryable-encryption.json # PYTHON-5143
116
rm $PYMONGO/test/discovery_and_monitoring/unified/pool-clear-application-error.json # PYTHON-4918
127
rm $PYMONGO/test/discovery_and_monitoring/unified/pool-clear-checkout-error.json # PYTHON-4918
138
rm $PYMONGO/test/discovery_and_monitoring/unified/pool-clear-min-pool-size-error.json # PYTHON-4918

.evergreen/run-tests.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ else
2626
fi
2727

2828
# List the packages.
29-
uv sync ${UV_ARGS} --reinstall
29+
uv sync ${UV_ARGS} --reinstall --quiet
3030
uv pip list
3131

32-
# Ensure we go back to base environment after the test.
33-
trap "uv sync" EXIT HUP
34-
3532
# Start the test runner.
3633
uv run ${UV_ARGS} .evergreen/scripts/run_tests.py "$@"
3734

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ jobs:
3838
build-mode: none
3939
steps:
4040
- name: Checkout repository
41-
uses: actions/checkout@v4
41+
uses: actions/checkout@v5
4242
with:
4343
ref: ${{ inputs.ref }}
4444
persist-credentials: false
4545
- uses: actions/setup-python@v5
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3
49+
uses: github/codeql-action/init@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3
5050
with:
5151
languages: ${{ matrix.language }}
5252
build-mode: ${{ matrix.build-mode }}
@@ -63,6 +63,6 @@ jobs:
6363
pip install -e .
6464
6565
- name: Perform CodeQL Analysis
66-
uses: github/codeql-action/analyze@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3
66+
uses: github/codeql-action/analyze@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3
6767
with:
6868
category: "/language:${{matrix.language}}"

.github/workflows/dist.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
steps:
4848
- name: Checkout pymongo
49-
uses: actions/checkout@v4
49+
uses: actions/checkout@v5
5050
with:
5151
fetch-depth: 0
5252
persist-credentials: false
@@ -109,7 +109,7 @@ jobs:
109109
name: Make SDist
110110
runs-on: macos-13
111111
steps:
112-
- uses: actions/checkout@v4
112+
- uses: actions/checkout@v5
113113
with:
114114
fetch-depth: 0
115115
persist-credentials: false

.github/workflows/test-python.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
static:
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@v5
2323
with:
2424
persist-credentials: false
2525
- name: Install uv
26-
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
26+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v5
2727
with:
2828
enable-cache: true
2929
python-version: "3.9"
@@ -61,11 +61,11 @@ jobs:
6161

6262
name: CPython ${{ matrix.python-version }}-${{ matrix.os }}
6363
steps:
64-
- uses: actions/checkout@v4
64+
- uses: actions/checkout@v5
6565
with:
6666
persist-credentials: false
6767
- name: Install uv
68-
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
68+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v5
6969
with:
7070
enable-cache: true
7171
python-version: ${{ matrix.python-version }}
@@ -80,11 +80,11 @@ jobs:
8080
runs-on: ubuntu-latest
8181
name: DocTest
8282
steps:
83-
- uses: actions/checkout@v4
83+
- uses: actions/checkout@v5
8484
with:
8585
persist-credentials: false
8686
- name: Install uv
87-
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
87+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v5
8888
with:
8989
enable-cache: true
9090
python-version: "3.9"
@@ -105,11 +105,11 @@ jobs:
105105
name: Docs Checks
106106
runs-on: ubuntu-latest
107107
steps:
108-
- uses: actions/checkout@v4
108+
- uses: actions/checkout@v5
109109
with:
110110
persist-credentials: false
111111
- name: Install uv
112-
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
112+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v5
113113
with:
114114
enable-cache: true
115115
python-version: "3.9"
@@ -124,11 +124,11 @@ jobs:
124124
name: Link Check
125125
runs-on: ubuntu-latest
126126
steps:
127-
- uses: actions/checkout@v4
127+
- uses: actions/checkout@v5
128128
with:
129129
persist-credentials: false
130130
- name: Install uv
131-
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
131+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v5
132132
with:
133133
enable-cache: true
134134
python-version: "3.9"
@@ -146,11 +146,11 @@ jobs:
146146
matrix:
147147
python: ["3.9", "3.11"]
148148
steps:
149-
- uses: actions/checkout@v4
149+
- uses: actions/checkout@v5
150150
with:
151151
persist-credentials: false
152152
- name: Install uv
153-
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
153+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v5
154154
with:
155155
enable-cache: true
156156
python-version: "${{matrix.python}}"
@@ -167,7 +167,7 @@ jobs:
167167
runs-on: ubuntu-latest
168168
name: "Make an sdist"
169169
steps:
170-
- uses: actions/checkout@v4
170+
- uses: actions/checkout@v5
171171
with:
172172
persist-credentials: false
173173
- uses: actions/setup-python@v5
@@ -225,11 +225,11 @@ jobs:
225225
runs-on: ubuntu-latest
226226
name: Test using minimum dependencies and supported Python
227227
steps:
228-
- uses: actions/checkout@v4
228+
- uses: actions/checkout@v5
229229
with:
230230
persist-credentials: false
231231
- name: Install uv
232-
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
232+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v5
233233
with:
234234
python-version: '3.9'
235235
- id: setup-mongodb
@@ -251,11 +251,11 @@ jobs:
251251
runs-on: ubuntu-latest
252252
name: Test async's minimum dependencies and Python
253253
steps:
254-
- uses: actions/checkout@v4
254+
- uses: actions/checkout@v5
255255
with:
256256
persist-credentials: false
257257
- name: Install uv
258-
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
258+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v5
259259
with:
260260
python-version: '3.9'
261261
- id: setup-mongodb

.github/workflows/zizmor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
security-events: write
1515
steps:
1616
- name: Checkout repository
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@v5
1818
with:
1919
persist-credentials: false
2020
- name: Run zizmor 🌈
21-
uses: zizmorcore/zizmor-action@383d31df2eb66a2f42db98c9654bdc73231f3e3a
21+
uses: zizmorcore/zizmor-action@7f2abfff7488a44086dba64ed2f5a9b431508079

bson/decimal128.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020

2121
import decimal
2222
import struct
23+
from decimal import Decimal
2324
from typing import Any, Sequence, Tuple, Type, Union
2425

26+
from bson.codec_options import TypeDecoder, TypeEncoder
27+
2528
_PACK_64 = struct.Struct("<Q").pack
2629
_UNPACK_64 = struct.Struct("<Q").unpack
2730

@@ -58,6 +61,42 @@
5861
_VALUE_OPTIONS = Union[decimal.Decimal, float, str, Tuple[int, Sequence[int], int]]
5962

6063

64+
class DecimalEncoder(TypeEncoder):
65+
"""Converts Python :class:`decimal.Decimal` to BSON :class:`Decimal128`.
66+
67+
For example::
68+
opts = CodecOptions(type_registry=TypeRegistry([DecimalEncoder()]))
69+
bson.encode({"d": decimal.Decimal('1.0')}, codec_options=opts)
70+
71+
.. versionadded:: 4.15
72+
"""
73+
74+
@property
75+
def python_type(self) -> Type[Decimal]:
76+
return Decimal
77+
78+
def transform_python(self, value: Any) -> Decimal128:
79+
return Decimal128(value)
80+
81+
82+
class DecimalDecoder(TypeDecoder):
83+
"""Converts BSON :class:`Decimal128` to Python :class:`decimal.Decimal`.
84+
85+
For example::
86+
opts = CodecOptions(type_registry=TypeRegistry([DecimalDecoder()]))
87+
bson.decode(data, codec_options=opts)
88+
89+
.. versionadded:: 4.15
90+
"""
91+
92+
@property
93+
def bson_type(self) -> Type[Decimal128]:
94+
return Decimal128
95+
96+
def transform_bson(self, value: Any) -> decimal.Decimal:
97+
return value.to_decimal()
98+
99+
61100
def create_decimal128_context() -> decimal.Context:
62101
"""Returns an instance of :class:`decimal.Context` appropriate
63102
for working with IEEE-754 128-bit decimal floating point values.

doc/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
Changelog
22
=========
3+
Changes in Version 4.15.0 (XXXX/XX/XX)
4+
--------------------------------------
5+
PyMongo 4.15 brings a number of changes including:
6+
7+
- Added :class:`bson.decimal128.DecimalEncoder` and :class:`bson.decimal128.DecimalDecoder`
8+
to support encoding and decoding of BSON Decimal128 values to decimal.Decimal values using the TypeRegistry API.
9+
310
Changes in Version 4.14.1 (2025/08/19)
411
--------------------------------------
512

justfile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set shell := ["bash", "-c"]
33

44
# Commonly used command segments.
5-
uv_run := "uv run --isolated --frozen "
5+
uv_run := "uv run --frozen "
66
typing_run := uv_run + "--group typing --extra aws --extra encryption --extra ocsp --extra snappy --extra test --extra zstd"
77
docs_run := uv_run + "--extra docs"
88
doc_build := "./doc/_build"
@@ -13,51 +13,55 @@ mypy_args := "--install-types --non-interactive"
1313
default:
1414
@just --list
1515

16+
[private]
17+
resync:
18+
@uv sync --quiet --frozen
19+
1620
install:
1721
bash .evergreen/scripts/setup-dev-env.sh
1822

1923
[group('docs')]
20-
docs:
24+
docs: && resync
2125
{{docs_run}} sphinx-build -W -b html doc {{doc_build}}/html
2226

2327
[group('docs')]
24-
docs-serve:
28+
docs-serve: && resync
2529
{{docs_run}} sphinx-autobuild -W -b html doc --watch ./pymongo --watch ./bson --watch ./gridfs {{doc_build}}/serve
2630

2731
[group('docs')]
28-
docs-linkcheck:
32+
docs-linkcheck: && resync
2933
{{docs_run}} sphinx-build -E -b linkcheck doc {{doc_build}}/linkcheck
3034

3135
[group('typing')]
32-
typing:
36+
typing: && resync
3337
just typing-mypy
3438
just typing-pyright
3539

3640
[group('typing')]
37-
typing-mypy:
41+
typing-mypy: && resync
3842
{{typing_run}} mypy {{mypy_args}} bson gridfs tools pymongo
3943
{{typing_run}} mypy {{mypy_args}} --config-file mypy_test.ini test
4044
{{typing_run}} mypy {{mypy_args}} test/test_typing.py test/test_typing_strict.py
4145

4246
[group('typing')]
43-
typing-pyright:
47+
typing-pyright: && resync
4448
{{typing_run}} pyright test/test_typing.py test/test_typing_strict.py
4549
{{typing_run}} pyright -p strict_pyrightconfig.json test/test_typing_strict.py
4650

4751
[group('lint')]
48-
lint:
52+
lint: && resync
4953
{{uv_run}} pre-commit run --all-files
5054

5155
[group('lint')]
52-
lint-manual:
56+
lint-manual: && resync
5357
{{uv_run}} pre-commit run --all-files --hook-stage manual
5458

5559
[group('test')]
56-
test *args="-v --durations=5 --maxfail=10":
60+
test *args="-v --durations=5 --maxfail=10": && resync
5761
{{uv_run}} --extra test pytest {{args}}
5862

5963
[group('test')]
60-
run-tests *args:
64+
run-tests *args: && resync
6165
bash ./.evergreen/run-tests.sh {{args}}
6266

6367
[group('test')]

pymongo/asynchronous/client_session.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@
167167
WTimeoutError,
168168
)
169169
from pymongo.helpers_shared import _RETRYABLE_ERROR_CODES
170-
from pymongo.operations import _Op
171170
from pymongo.read_concern import ReadConcern
172171
from pymongo.read_preferences import ReadPreference, _ServerMode
173172
from pymongo.server_type import SERVER_TYPE
@@ -868,7 +867,7 @@ async def func(
868867
return await self._finish_transaction(conn, command_name)
869868

870869
return await self._client._retry_internal(
871-
func, self, None, retryable=True, operation=_Op.ABORT
870+
func, self, None, retryable=True, operation=command_name
872871
)
873872

874873
async def _finish_transaction(self, conn: AsyncConnection, command_name: str) -> dict[str, Any]:

0 commit comments

Comments
 (0)