Skip to content

Commit f7d2deb

Browse files
authored
PYTHON-4480 Deprecate create=True for Collection (mongodb#1659)
1 parent f7faff8 commit f7d2deb

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

pymongo/asynchronous/collection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Collection level utilities for Mongo."""
1616
from __future__ import annotations
1717

18+
import warnings
1819
from collections import abc
1920
from typing import (
2021
TYPE_CHECKING,
@@ -248,6 +249,11 @@ def __init__(
248249

249250
if create or kwargs:
250251
if _IS_SYNC:
252+
warnings.warn(
253+
"The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0",
254+
DeprecationWarning,
255+
stacklevel=2,
256+
)
251257
self._create(kwargs, session) # type: ignore[unused-coroutine]
252258
else:
253259
raise ValueError(

pymongo/synchronous/collection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Collection level utilities for Mongo."""
1616
from __future__ import annotations
1717

18+
import warnings
1819
from collections import abc
1920
from typing import (
2021
TYPE_CHECKING,
@@ -251,6 +252,11 @@ def __init__(
251252

252253
if create or kwargs:
253254
if _IS_SYNC:
255+
warnings.warn(
256+
"The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0",
257+
DeprecationWarning,
258+
stacklevel=2,
259+
)
254260
self._create(kwargs, session) # type: ignore[unused-coroutine]
255261
else:
256262
raise ValueError("Collection does not support the `create` or `kwargs` arguments.")

test/test_collection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ def test_create(self):
198198
"create create_test_no_wc collection",
199199
)
200200
db.create_test_no_wc.drop()
201-
Collection(db, name="create_test_no_wc", create=True)
201+
with self.assertWarns(
202+
DeprecationWarning,
203+
msg="The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0",
204+
):
205+
Collection(db, name="create_test_no_wc", create=True)
202206
wait_until(
203207
lambda: "create_test_no_wc" in db.list_collection_names(),
204208
"create create_test_no_wc collection",

0 commit comments

Comments
 (0)