Skip to content

Commit cb075e5

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents 7eafd5d + 6862e94 commit cb075e5

18 files changed

+497
-121
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Create Release Branch
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch_name:
7+
description: The name of the new branch
8+
required: true
9+
version:
10+
description: The version to set on the branch
11+
required: true
12+
base_ref:
13+
description: The base reference for the branch
14+
push_changes:
15+
description: Whether to push the changes
16+
default: "true"
17+
18+
concurrency:
19+
group: create-branch-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
defaults:
23+
run:
24+
shell: bash -eux {0}
25+
26+
jobs:
27+
create-branch:
28+
environment: release
29+
runs-on: ubuntu-latest
30+
permissions:
31+
id-token: write
32+
contents: write
33+
outputs:
34+
version: ${{ steps.pre-publish.outputs.version }}
35+
steps:
36+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
37+
with:
38+
app_id: ${{ vars.APP_ID }}
39+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
40+
- uses: mongodb-labs/drivers-github-tools/setup@v2
41+
with:
42+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
43+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
44+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
45+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
46+
- uses: mongodb-labs/drivers-github-tools/create-branch@v2
47+
id: create-branch
48+
with:
49+
branch_name: ${{ inputs.branch_name }}
50+
version: ${{ inputs.version }}
51+
base_ref: ${{ inputs.base_ref }}
52+
push_changes: ${{ inputs.push_changes }}
53+
version_bump_script: hatch version
54+
evergreen_project: mongo-python-driver-release
55+
release_workflow_path: ./.github/workflows/release-python.yml

bson/json_util.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -617,25 +617,28 @@ def _parse_canonical_datetime(
617617
raise TypeError(f"Bad $date, extra field(s): {doc}")
618618
# mongoexport 2.6 and newer
619619
if isinstance(dtm, str):
620-
# Parse offset
621-
if dtm[-1] == "Z":
622-
dt = dtm[:-1]
623-
offset = "Z"
624-
elif dtm[-6] in ("+", "-") and dtm[-3] == ":":
625-
# (+|-)HH:MM
626-
dt = dtm[:-6]
627-
offset = dtm[-6:]
628-
elif dtm[-5] in ("+", "-"):
629-
# (+|-)HHMM
630-
dt = dtm[:-5]
631-
offset = dtm[-5:]
632-
elif dtm[-3] in ("+", "-"):
633-
# (+|-)HH
634-
dt = dtm[:-3]
635-
offset = dtm[-3:]
636-
else:
637-
dt = dtm
638-
offset = ""
620+
try:
621+
# Parse offset
622+
if dtm[-1] == "Z":
623+
dt = dtm[:-1]
624+
offset = "Z"
625+
elif dtm[-6] in ("+", "-") and dtm[-3] == ":":
626+
# (+|-)HH:MM
627+
dt = dtm[:-6]
628+
offset = dtm[-6:]
629+
elif dtm[-5] in ("+", "-"):
630+
# (+|-)HHMM
631+
dt = dtm[:-5]
632+
offset = dtm[-5:]
633+
elif dtm[-3] in ("+", "-"):
634+
# (+|-)HH
635+
dt = dtm[:-3]
636+
offset = dtm[-3:]
637+
else:
638+
dt = dtm
639+
offset = ""
640+
except IndexError as exc:
641+
raise ValueError(f"time data {dtm!r} does not match ISO-8601 datetime format") from exc
639642

640643
# Parse the optional factional seconds portion.
641644
dot_index = dt.rfind(".")
@@ -848,7 +851,7 @@ def _encode_datetimems(obj: Any, json_options: JSONOptions) -> dict:
848851
):
849852
return _encode_datetime(obj.as_datetime(), json_options)
850853
elif json_options.datetime_representation == DatetimeRepresentation.LEGACY:
851-
return {"$date": str(int(obj))}
854+
return {"$date": int(obj)}
852855
return {"$date": {"$numberLong": str(int(obj))}}
853856

854857

doc/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ PyMongo 4.11 brings a number of changes including:
2828
:meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.bulk_write` now throw an error
2929
when ``ordered=True`` or ``verboseResults=True`` are used with unacknowledged writes.
3030
These are unavoidable breaking changes.
31+
- Fixed a bug in :const:`bson.json_util.dumps` where a :class:`bson.datetime_ms.DatetimeMS` would
32+
be incorrectly encoded as ``'{"$date": "X"}'`` instead of ``'{"$date": X}'`` when using the
33+
legacy MongoDB Extended JSON datetime representation.
34+
- Fixed a bug where :const:`bson.json_util.loads` would raise an IndexError when parsing an invalid
35+
``"$date"`` instead of a ValueError.
3136

3237
Issues Resolved
3338
...............
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
{
2+
"description": "create-null-ids",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client",
8+
"observeEvents": [
9+
"commandStartedEvent"
10+
]
11+
}
12+
},
13+
{
14+
"database": {
15+
"id": "database",
16+
"client": "client",
17+
"databaseName": "crud_id"
18+
}
19+
},
20+
{
21+
"collection": {
22+
"id": "collection",
23+
"database": "database",
24+
"collectionName": "type_tests"
25+
}
26+
}
27+
],
28+
"initialData": [
29+
{
30+
"collectionName": "type_tests",
31+
"databaseName": "crud_id",
32+
"documents": []
33+
}
34+
],
35+
"tests": [
36+
{
37+
"description": "inserting _id with type null via insertOne",
38+
"operations": [
39+
{
40+
"name": "insertOne",
41+
"object": "collection",
42+
"arguments": {
43+
"document": {
44+
"_id": null
45+
}
46+
}
47+
},
48+
{
49+
"name": "countDocuments",
50+
"object": "collection",
51+
"arguments": {
52+
"filter": {
53+
"_id": {
54+
"$type": "null"
55+
}
56+
}
57+
},
58+
"expectResult": 1
59+
}
60+
]
61+
},
62+
{
63+
"description": "inserting _id with type null via insertMany",
64+
"operations": [
65+
{
66+
"name": "insertMany",
67+
"object": "collection",
68+
"arguments": {
69+
"documents": [
70+
{
71+
"_id": null
72+
}
73+
]
74+
}
75+
},
76+
{
77+
"name": "countDocuments",
78+
"object": "collection",
79+
"arguments": {
80+
"filter": {
81+
"_id": {
82+
"$type": "null"
83+
}
84+
}
85+
},
86+
"expectResult": 1
87+
}
88+
]
89+
},
90+
{
91+
"description": "inserting _id with type null via updateOne",
92+
"operations": [
93+
{
94+
"name": "updateOne",
95+
"object": "collection",
96+
"arguments": {
97+
"filter": {
98+
"_id": null
99+
},
100+
"update": {
101+
"$unset": {
102+
"a": ""
103+
}
104+
},
105+
"upsert": true
106+
}
107+
},
108+
{
109+
"name": "countDocuments",
110+
"object": "collection",
111+
"arguments": {
112+
"filter": {
113+
"_id": {
114+
"$type": "null"
115+
}
116+
}
117+
},
118+
"expectResult": 1
119+
}
120+
]
121+
},
122+
{
123+
"description": "inserting _id with type null via updateMany",
124+
"operations": [
125+
{
126+
"name": "updateMany",
127+
"object": "collection",
128+
"arguments": {
129+
"filter": {
130+
"_id": null
131+
},
132+
"update": {
133+
"$unset": {
134+
"a": ""
135+
}
136+
},
137+
"upsert": true
138+
}
139+
},
140+
{
141+
"name": "countDocuments",
142+
"object": "collection",
143+
"arguments": {
144+
"filter": {
145+
"_id": {
146+
"$type": "null"
147+
}
148+
}
149+
},
150+
"expectResult": 1
151+
}
152+
]
153+
},
154+
{
155+
"description": "inserting _id with type null via replaceOne",
156+
"operations": [
157+
{
158+
"name": "replaceOne",
159+
"object": "collection",
160+
"arguments": {
161+
"filter": {},
162+
"replacement": {
163+
"_id": null
164+
},
165+
"upsert": true
166+
}
167+
},
168+
{
169+
"name": "countDocuments",
170+
"object": "collection",
171+
"arguments": {
172+
"filter": {
173+
"_id": {
174+
"$type": "null"
175+
}
176+
}
177+
},
178+
"expectResult": 1
179+
}
180+
]
181+
},
182+
{
183+
"description": "inserting _id with type null via bulkWrite",
184+
"operations": [
185+
{
186+
"name": "bulkWrite",
187+
"object": "collection",
188+
"arguments": {
189+
"requests": [
190+
{
191+
"insertOne": {
192+
"document": {
193+
"_id": null
194+
}
195+
}
196+
}
197+
]
198+
}
199+
},
200+
{
201+
"name": "countDocuments",
202+
"object": "collection",
203+
"arguments": {
204+
"filter": {
205+
"_id": {
206+
"$type": "null"
207+
}
208+
}
209+
},
210+
"expectResult": 1
211+
}
212+
]
213+
},
214+
{
215+
"description": "inserting _id with type null via clientBulkWrite",
216+
"runOnRequirements": [
217+
{
218+
"minServerVersion": "8.0"
219+
}
220+
],
221+
"operations": [
222+
{
223+
"name": "clientBulkWrite",
224+
"object": "client",
225+
"arguments": {
226+
"models": [
227+
{
228+
"insertOne": {
229+
"namespace": "crud_id.type_tests",
230+
"document": {
231+
"_id": null
232+
}
233+
}
234+
}
235+
]
236+
}
237+
},
238+
{
239+
"name": "countDocuments",
240+
"object": "collection",
241+
"arguments": {
242+
"filter": {
243+
"_id": {
244+
"$type": "null"
245+
}
246+
}
247+
},
248+
"expectResult": 1
249+
}
250+
]
251+
}
252+
]
253+
}

0 commit comments

Comments
 (0)