PYTHON-4057 Emit DeprecationWarning for deprecated GridFS apis (#1593)

This commit is contained in:
Steven Silvester 2024-04-16 11:02:05 -05:00 committed by GitHub
parent 09e24a4bea
commit 8f7b86f3f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import datetime
import io
import math
import os
import warnings
from typing import Any, Iterable, Mapping, NoReturn, Optional
from bson.int64 import Int64
@ -69,8 +70,15 @@ def _grid_in_property(
closed_only: Optional[bool] = False,
) -> Any:
"""Create a GridIn property."""
warn_str = ""
if docstring.startswith("DEPRECATED,"):
warn_str = (
f"GridIn property '{field_name}' is deprecated and will be removed in PyMongo 5.0"
)
def getter(self: Any) -> Any:
if warn_str:
warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning)
if closed_only and not self._closed:
raise AttributeError("can only get %r on a closed file" % field_name)
# Protect against PHP-237
@ -79,6 +87,8 @@ def _grid_in_property(
return self._file.get(field_name, None)
def setter(self: Any, value: Any) -> Any:
if warn_str:
warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning)
if self._closed:
self._coll.files.update_one({"_id": self._file["_id"]}, {"$set": {field_name: value}})
self._file[field_name] = value
@ -100,8 +110,15 @@ def _grid_in_property(
def _grid_out_property(field_name: str, docstring: str) -> Any:
"""Create a GridOut property."""
warn_str = ""
if docstring.startswith("DEPRECATED,"):
warn_str = (
f"GridOut property '{field_name}' is deprecated and will be removed in PyMongo 5.0"
)
def getter(self: Any) -> Any:
if warn_str:
warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning)
self._ensure_file()
# Protect against PHP-237

View File

@ -115,6 +115,8 @@ filterwarnings = [
"module:Unsupported compressor:UserWarning",
"module:zlibcompressionlevel must be:UserWarning",
"module:Wire protocol compression with:UserWarning",
"module:GridIn property:DeprecationWarning",
"module:GridOut property:DeprecationWarning",
# TODO: Remove as part of PYTHON-3923.
"module:unclosed <eventlet.green.ssl.GreenSSLSocket:ResourceWarning",
"module:unclosed <socket.socket:ResourceWarning",