Skip to content

Commit 2a58cc3

Browse files
authored
Merge branch 'master' into dependabot/pip/mypy-1.18.2
2 parents d673006 + 29c4c2c commit 2a58cc3

19 files changed

+214
-112
lines changed

.evergreen/scripts/setup-dev-env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ if [ -f $HOME/.visualStudioEnv.sh ]; then
4747
SSH_TTY=1 source $HOME/.visualStudioEnv.sh
4848
set -u
4949
fi
50-
uv sync --frozen
50+
uv sync
5151

5252
echo "Setting up python environment... done."
5353

5454
# Ensure there is a pre-commit hook if there is a git checkout.
5555
if [ -d .git ] && [ ! -f .git/hooks/pre-commit ]; then
56-
uv run --frozen pre-commit install
56+
uv run pre-commit install
5757
fi
5858

5959
popd > /dev/null

.github/workflows/create-release-branch.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ jobs:
3333
outputs:
3434
version: ${{ steps.pre-publish.outputs.version }}
3535
steps:
36-
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
36+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v3
3737
with:
3838
app_id: ${{ vars.APP_ID }}
3939
private_key: ${{ secrets.APP_PRIVATE_KEY }}
40-
- uses: mongodb-labs/drivers-github-tools/setup@v2
40+
- uses: mongodb-labs/drivers-github-tools/setup@v3
4141
with:
4242
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
4343
aws_region_name: ${{ vars.AWS_REGION_NAME }}
4444
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
4545
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
4646
- name: Get hatch
4747
run: pip install hatch
48-
- uses: mongodb-labs/drivers-github-tools/create-branch@v2
48+
- uses: mongodb-labs/drivers-github-tools/create-branch@v3
4949
id: create-branch
5050
with:
5151
branch_name: ${{ inputs.branch_name }}

.github/workflows/release-python.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ jobs:
3838
outputs:
3939
version: ${{ steps.pre-publish.outputs.version }}
4040
steps:
41-
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
41+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v3
4242
with:
4343
app_id: ${{ vars.APP_ID }}
4444
private_key: ${{ secrets.APP_PRIVATE_KEY }}
45-
- uses: mongodb-labs/drivers-github-tools/setup@v2
45+
- uses: mongodb-labs/drivers-github-tools/setup@v3
4646
with:
4747
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
4848
aws_region_name: ${{ vars.AWS_REGION_NAME }}
4949
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
50-
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
51-
- uses: mongodb-labs/drivers-github-tools/python/pre-publish@v2
50+
- uses: mongodb-labs/drivers-github-tools/python/pre-publish@v3
5251
id: pre-publish
5352
with:
5453
dry_run: ${{ env.DRY_RUN }}
@@ -100,17 +99,16 @@ jobs:
10099
attestations: write
101100
security-events: write
102101
steps:
103-
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
102+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v3
104103
with:
105104
app_id: ${{ vars.APP_ID }}
106105
private_key: ${{ secrets.APP_PRIVATE_KEY }}
107-
- uses: mongodb-labs/drivers-github-tools/setup@v2
106+
- uses: mongodb-labs/drivers-github-tools/setup@v3
108107
with:
109108
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
110109
aws_region_name: ${{ vars.AWS_REGION_NAME }}
111110
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
112-
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
113-
- uses: mongodb-labs/drivers-github-tools/python/post-publish@v2
111+
- uses: mongodb-labs/drivers-github-tools/python/post-publish@v3
114112
with:
115113
following_version: ${{ env.FOLLOWING_VERSION }}
116114
product_name: ${{ env.PRODUCT_NAME }}

.github/workflows/zizmor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
with:
1919
persist-credentials: false
2020
- name: Run zizmor 🌈
21-
uses: zizmorcore/zizmor-action@873539476a7f9b0da7504d0d9e9a6a5275094d98
21+
uses: zizmorcore/zizmor-action@0696496a48b64e0568faa46ddaf5f6fe48b83b04

.pre-commit-config.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ repos:
105105
# - test/test_client.py:188: te ==> the, be, we, to
106106
args: ["-L", "fle,fo,infinit,isnt,nin,te,aks"]
107107

108-
- repo: https://github.com/astral-sh/uv-pre-commit
109-
# uv version.
110-
rev: 0.8.17
111-
hooks:
112-
- id: uv-lock
113-
114108
- repo: local
115109
hooks:
116110
- id: executable-shell
@@ -128,3 +122,14 @@ repos:
128122
language: python
129123
require_serial: true
130124
additional_dependencies: ["shrub.py>=3.10.0", "pyyaml>=6.0.2"]
125+
126+
- id: uv-lock
127+
name: uv-lock
128+
entry: uv lock
129+
language: python
130+
require_serial: true
131+
files: ^(uv\.lock|pyproject\.toml|requirements.txt|requirements/.*\.txt)$
132+
pass_filenames: false
133+
fail_fast: true
134+
additional_dependencies:
135+
- "uv>=0.8.4"

bson/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ def _dict_to_bson(
10091009
try:
10101010
elements.append(_element_to_bson(key, value, check_keys, opts))
10111011
except InvalidDocument as err:
1012-
raise InvalidDocument(f"Invalid document {doc} | {err}") from err
1012+
raise InvalidDocument(f"Invalid document: {err}", doc) from err
10131013
except AttributeError:
10141014
raise TypeError(f"encoder expected a mapping type but got: {doc!r}") from None
10151015

bson/_cbsonmodule.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,11 +1645,11 @@ static int write_raw_doc(buffer_t buffer, PyObject* raw, PyObject* _raw_str) {
16451645
}
16461646

16471647

1648-
/* Update Invalid Document error message to include doc.
1648+
/* Update Invalid Document error to include doc as a property.
16491649
*/
16501650
void handle_invalid_doc_error(PyObject* dict) {
16511651
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
1652-
PyObject *msg = NULL, *dict_str = NULL, *new_msg = NULL;
1652+
PyObject *msg = NULL, *new_msg = NULL, *new_evalue = NULL;
16531653
PyErr_Fetch(&etype, &evalue, &etrace);
16541654
PyObject *InvalidDocument = _error("InvalidDocument");
16551655
if (InvalidDocument == NULL) {
@@ -1659,26 +1659,22 @@ void handle_invalid_doc_error(PyObject* dict) {
16591659
if (evalue && PyErr_GivenExceptionMatches(etype, InvalidDocument)) {
16601660
PyObject *msg = PyObject_Str(evalue);
16611661
if (msg) {
1662-
// Prepend doc to the existing message
1663-
PyObject *dict_str = PyObject_Str(dict);
1664-
if (dict_str == NULL) {
1665-
goto cleanup;
1666-
}
1667-
const char * dict_str_utf8 = PyUnicode_AsUTF8(dict_str);
1668-
if (dict_str_utf8 == NULL) {
1669-
goto cleanup;
1670-
}
16711662
const char * msg_utf8 = PyUnicode_AsUTF8(msg);
16721663
if (msg_utf8 == NULL) {
16731664
goto cleanup;
16741665
}
1675-
PyObject *new_msg = PyUnicode_FromFormat("Invalid document %s | %s", dict_str_utf8, msg_utf8);
1666+
PyObject *new_msg = PyUnicode_FromFormat("Invalid document: %s", msg_utf8);
1667+
if (new_msg == NULL) {
1668+
goto cleanup;
1669+
}
1670+
// Add doc to the error instance as a property.
1671+
PyObject *new_evalue = PyObject_CallFunctionObjArgs(InvalidDocument, new_msg, dict, NULL);
16761672
Py_DECREF(evalue);
16771673
Py_DECREF(etype);
16781674
etype = InvalidDocument;
16791675
InvalidDocument = NULL;
1680-
if (new_msg) {
1681-
evalue = new_msg;
1676+
if (new_evalue) {
1677+
evalue = new_evalue;
16821678
} else {
16831679
evalue = msg;
16841680
}
@@ -1689,7 +1685,7 @@ void handle_invalid_doc_error(PyObject* dict) {
16891685
PyErr_Restore(etype, evalue, etrace);
16901686
Py_XDECREF(msg);
16911687
Py_XDECREF(InvalidDocument);
1692-
Py_XDECREF(dict_str);
1688+
Py_XDECREF(new_evalue);
16931689
Py_XDECREF(new_msg);
16941690
}
16951691

bson/errors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"""Exceptions raised by the BSON package."""
1616
from __future__ import annotations
1717

18+
from typing import Any, Optional
19+
1820

1921
class BSONError(Exception):
2022
"""Base class for all BSON exceptions."""
@@ -31,6 +33,17 @@ class InvalidStringData(BSONError):
3133
class InvalidDocument(BSONError):
3234
"""Raised when trying to create a BSON object from an invalid document."""
3335

36+
def __init__(self, message: str, document: Optional[Any] = None) -> None:
37+
super().__init__(message)
38+
self._document = document
39+
40+
@property
41+
def document(self) -> Any:
42+
"""The invalid document that caused the error.
43+
44+
..versionadded:: 4.16"""
45+
return self._document
46+
3447

3548
class InvalidId(BSONError):
3649
"""Raised when trying to create an ObjectId from invalid data."""

doc/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
Changes in Version 4.16.0 (XXXX/XX/XX)
5+
--------------------------------------
6+
7+
PyMongo 4.16 brings a number of changes including:
8+
9+
- Removed invalid documents from :class:`bson.errors.InvalidDocument` error messages as
10+
doing so may leak sensitive user data.
11+
Instead, invalid documents are stored in :attr:`bson.errors.InvalidDocument.document`.
12+
413
Changes in Version 4.15.1 (2025/09/16)
514
--------------------------------------
615

justfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# See https://just.systems/man/en/ for instructions
22
set shell := ["bash", "-c"]
3-
# Do not modify the lock file when running justfile commands.
4-
export UV_FROZEN := "1"
53

64
# Commonly used command segments.
75
typing_run := "uv run --group typing --extra aws --extra encryption --extra ocsp --extra snappy --extra test --extra zstd"
@@ -16,7 +14,7 @@ default:
1614

1715
[private]
1816
resync:
19-
@uv sync --quiet --frozen
17+
@uv sync --quiet
2018

2119
install:
2220
bash .evergreen/scripts/setup-dev-env.sh

0 commit comments

Comments
 (0)