PYTHON-4480 Deprecate create=True for Collection (#1659)

This commit is contained in:
Noah Stapp 2024-06-10 12:31:19 -07:00 committed by GitHub
parent f7faff829c
commit f7d2deb27d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 1 deletions

View File

@ -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(

View File

@ -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.")

View File

@ -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",