PYTHON-4480 Deprecate create=True for Collection (#1659)
This commit is contained in:
parent
f7faff829c
commit
f7d2deb27d
@ -15,6 +15,7 @@
|
||||
"""Collection level utilities for Mongo."""
|
||||
from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
from collections import abc
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
@ -248,6 +249,11 @@ class AsyncCollection(common.BaseObject, Generic[_DocumentType]):
|
||||
|
||||
if create or kwargs:
|
||||
if _IS_SYNC:
|
||||
warnings.warn(
|
||||
"The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._create(kwargs, session) # type: ignore[unused-coroutine]
|
||||
else:
|
||||
raise ValueError(
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
"""Collection level utilities for Mongo."""
|
||||
from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
from collections import abc
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
@ -251,6 +252,11 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
|
||||
|
||||
if create or kwargs:
|
||||
if _IS_SYNC:
|
||||
warnings.warn(
|
||||
"The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._create(kwargs, session) # type: ignore[unused-coroutine]
|
||||
else:
|
||||
raise ValueError("Collection does not support the `create` or `kwargs` arguments.")
|
||||
|
||||
@ -198,7 +198,11 @@ class TestCollection(IntegrationTest):
|
||||
"create create_test_no_wc collection",
|
||||
)
|
||||
db.create_test_no_wc.drop()
|
||||
Collection(db, name="create_test_no_wc", create=True)
|
||||
with self.assertWarns(
|
||||
DeprecationWarning,
|
||||
msg="The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0",
|
||||
):
|
||||
Collection(db, name="create_test_no_wc", create=True)
|
||||
wait_until(
|
||||
lambda: "create_test_no_wc" in db.list_collection_names(),
|
||||
"create create_test_no_wc collection",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user