Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .evergreen/generated_configs/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4816,29 +4816,6 @@ tasks:
- sync
- free-threaded

# String query preview tests
- name: test-string-query-preview-v8.2-python3.15-noauth-ssl-replica-set
commands:
- func: run server
vars:
AUTH: noauth
SSL: ssl
TOPOLOGY: replica_set
VERSION: "8.2"
- func: run tests
vars:
AUTH: noauth
SSL: ssl
TOPOLOGY: replica_set
VERSION: "8.2"
UV_PYTHON: "3.15"
tags:
- test-string-query-preview
- server-8.2
- python-3.15
- replica_set-noauth-ssl
- noauth

# Test non standard tests
- name: test-non-standard-v4.4-python3.12-noauth-ssl-replica-set
commands:
Expand Down
6 changes: 0 additions & 6 deletions .evergreen/generated_configs/variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ buildvariants:
- name: encryption-rhel8
tasks:
- name: .test-non-standard !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption RHEL8
run_on:
- rhel8.10-small
Expand All @@ -198,7 +197,6 @@ buildvariants:
tasks:
- name: .test-non-standard !.cov !.python-3.15t
- name: .test-non-standard-no-cov !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption macOS
run_on:
- macos-14
Expand All @@ -210,7 +208,6 @@ buildvariants:
tasks:
- name: .test-non-standard !.cov !.python-3.15t
- name: .test-non-standard-no-cov !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption Win64
run_on:
- windows-2022-latest-small
Expand All @@ -221,7 +218,6 @@ buildvariants:
- name: encryption-crypt_shared-rhel8
tasks:
- name: .test-non-standard !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption crypt_shared RHEL8
run_on:
- rhel8.10-small
Expand All @@ -234,7 +230,6 @@ buildvariants:
tasks:
- name: .test-non-standard !.cov !.python-3.15t
- name: .test-non-standard-no-cov !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption crypt_shared macOS
run_on:
- macos-14
Expand All @@ -247,7 +242,6 @@ buildvariants:
tasks:
- name: .test-non-standard !.cov !.python-3.15t
- name: .test-non-standard-no-cov !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption crypt_shared Win64
run_on:
- windows-2022-latest-small
Expand Down
31 changes: 1 addition & 30 deletions .evergreen/scripts/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get_encryption_expansions(encryption):
):
expansions = get_encryption_expansions(encryption)
display_name = get_variant_name(encryption, host, **expansions)
tasks = [".test-non-standard !.python-3.15t", ".test-string-query-preview"]
tasks = [".test-non-standard !.python-3.15t"]
if host != "rhel8":
# Exclude coverage tasks (encryption suites exceed the 60-min timeout with
# coverage overhead on macOS/win64).
Expand All @@ -160,7 +160,6 @@ def get_encryption_expansions(encryption):
tasks = [
".test-non-standard !.cov !.python-3.15t",
".test-non-standard-no-cov !.python-3.15t",
".test-string-query-preview",
]
variant = create_variant(
tasks,
Expand Down Expand Up @@ -822,34 +821,6 @@ def create_test_non_standard_tasks():
return tasks


def create_string_query_preview_tasks():
"""Tasks for the preview Queryable Encryption string query types.

The preview query types need a server that is at least 8.2 and older than
9.0, and ALL_VERSIONS jumps straight from 8.0 to 9.0, so they have nowhere
to run without a dedicated task. setup_tests.py pins the released
pymongocrypt for 8.x, which bundles a libmongocrypt still carrying the
preview types.
"""
python = CPYTHONS[-1]
topology = "replica_set"
auth, ssl = get_standard_auth_ssl(topology)
expansions = dict(AUTH=auth, SSL=ssl, TOPOLOGY=topology, VERSION="8.2")
tags = [
"test-string-query-preview",
"server-8.2",
f"python-{python}",
f"{topology}-{auth}-{ssl}",
auth,
]
name = get_task_name("test-string-query-preview", python=python, **expansions)
server_func = FunctionCall(func="run server", vars=expansions)
test_vars = expansions.copy()
test_vars["UV_PYTHON"] = python
test_func = FunctionCall(func="run tests", vars=test_vars)
return [EvgTask(name=name, tags=tags, commands=[server_func, test_func])]


def create_test_standard_auth_tasks():
"""We only use auth on sharded clusters"""
tasks = []
Expand Down
64 changes: 27 additions & 37 deletions .evergreen/scripts/setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
GROUP_MAP = dict(fuzz="fuzz", mockupdb="mockupdb", perf="perf")

# The libmongocrypt release used when LIBMONGOCRYPT_URL is not set. Must be at
# least 1.20.0 for the GA "substring" query type.
LIBMONGOCRYPT_VERSION = "1.20.2"
# least 1.21.0; the beta preview string query types were removed in 1.21.0
# (MONGOCRYPT-938).
LIBMONGOCRYPT_VERSION = "1.21.0"


def is_set(var: str) -> bool:
Expand Down Expand Up @@ -390,44 +391,33 @@ def handle_test_env() -> None:
UV_ARGS.append("--extra zstd")

if test_name in ["encryption", "kms"]:
# The "String" algorithm and the GA prefix/suffix/substring query types
# need libmongocrypt 1.19.0+, which is only exercised against MongoDB
# 9.0+. Servers before 9.0 test the preview query types instead, which
# need the "textPreview" algorithm, so pin to the released pymongocrypt
# and use the libmongocrypt bundled in its wheel rather than the
# unreleased master build.
# Evergreen exposes the server version as VERSION, not MONGODB_VERSION
# (which is only set inside the separate run_server.py process).
use_pymongocrypt_text_preview = os.environ.get("VERSION", "").startswith("8.")

if not use_pymongocrypt_text_preview:
# Check for libmongocrypt download.
if not (ROOT / "libmongocrypt").exists():
setup_libmongocrypt()
# The GA string query types need libmongocrypt 1.19.0+ and the beta
# preview query types were removed in 1.21.0 (PYTHON-5959), so always
# use the master pymongocrypt build against the pinned libmongocrypt
# rather than the lib bundled in the released wheel.
# Check for libmongocrypt download.
if not (ROOT / "libmongocrypt").exists():
setup_libmongocrypt()

if not opts.test_min_deps:
if use_pymongocrypt_text_preview:
UV_ARGS.append("--with pymongocrypt<1.19")
else:
UV_ARGS.append(
"--with pymongocrypt@git+https://github.com/mongodb/libmongocrypt@master#subdirectory=bindings/python"
)

if not use_pymongocrypt_text_preview:
# Use the nocrypto build to avoid dependency issues with older windows/python versions.
BASE = get_libmongocrypt_base()
if PLATFORM == "linux":
if (BASE / "lib/libmongocrypt.so").exists():
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.so"
else:
PYMONGOCRYPT_LIB = BASE / "lib64/libmongocrypt.so"
elif PLATFORM == "darwin":
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.dylib"
UV_ARGS.append(
"--with pymongocrypt@git+https://github.com/mongodb/libmongocrypt@master#subdirectory=bindings/python"
)

# Use the nocrypto build to avoid dependency issues with older windows/python versions.
BASE = get_libmongocrypt_base()
if PLATFORM == "linux":
if (BASE / "lib/libmongocrypt.so").exists():
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.so"
else:
PYMONGOCRYPT_LIB = BASE / "bin/mongocrypt.dll"
if not PYMONGOCRYPT_LIB.exists():
raise RuntimeError("Cannot find libmongocrypt shared object file")
write_env("PYMONGOCRYPT_LIB", PYMONGOCRYPT_LIB.as_posix())
PYMONGOCRYPT_LIB = BASE / "lib64/libmongocrypt.so"
elif PLATFORM == "darwin":
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.dylib"
else:
PYMONGOCRYPT_LIB = BASE / "bin/mongocrypt.dll"
if not PYMONGOCRYPT_LIB.exists():
raise RuntimeError("Cannot find libmongocrypt shared object file")
write_env("PYMONGOCRYPT_LIB", PYMONGOCRYPT_LIB.as_posix())
# PATH is updated by configure-env.sh for access to mongocryptd.

if test_name == "encryption":
Expand Down
12 changes: 12 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ Changes in Version 4.20.0 (2026/XX/XX)

- The client handshake metadata now reports a detected coding agent in
``client.env.agent`` (`PYTHON-5929`_).
- Removed the beta ``QueryType.PREFIXPREVIEW``, ``QueryType.SUFFIXPREVIEW``,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should all use Sphinx role cross-references as per CODING-STANDARDS.md.

@blink1073 blink1073 Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't link to things that are removed

and ``QueryType.SUBSTRINGPREVIEW`` query types. Use
:attr:`~pymongo.encryption.QueryType.PREFIX`,
:attr:`~pymongo.encryption.QueryType.SUFFIX`, and
:attr:`~pymongo.encryption.QueryType.SUBSTRING` instead (requires MongoDB
9.0+ and pymongocrypt 1.21.0+) (`PYTHON-5959`_).
Comment on lines +9 to +14

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention that this change also removes support for text_opts in favor of string_opts due to the pymongocrypt version bump.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

- Removed the deprecated ``text_opts`` parameter of
:meth:`~pymongo.encryption.ClientEncryption.encrypt` and
:meth:`~pymongo.asynchronous.encryption.AsyncClientEncryption.encrypt`, and
the ``TextOpts`` class. Use ``string_opts`` and
:class:`~pymongo.encryption_options.StringOpts` instead (`PYTHON-5959`_).

Bug fixes
.........
Expand Down Expand Up @@ -36,6 +47,7 @@ Bug fixes
Users of Python 3.12 and 3.13 should upgrade to at least those versions (`PYTHON-6182`_).

.. _PYTHON-5929: https://jira.mongodb.org/browse/PYTHON-5929
.. _PYTHON-5959: https://jira.mongodb.org/browse/PYTHON-5959
.. _PYTHON-6172: https://jira.mongodb.org/browse/PYTHON-6172
.. _PYTHON-6149: https://jira.mongodb.org/browse/PYTHON-6149
.. _PYTHON-5873: https://jira.mongodb.org/browse/PYTHON-5873
Expand Down
57 changes: 5 additions & 52 deletions pymongo/asynchronous/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import asyncio
import functools
import time as time # noqa: PLC0414 # needed in sync version
import uuid
import weakref
Expand Down Expand Up @@ -61,9 +60,6 @@
AutoEncryptionOpts,
RangeOpts,
StringOpts,
# Re-exported for backwards compatibility: TextOpts is deprecated but must
# remain importable from this module until it is removed.
TextOpts, # noqa: F401
check_min_pymongocrypt,
)
from pymongo.encryption_shared import (
Expand Down Expand Up @@ -468,47 +464,6 @@ async def close(self) -> None:
self._internal_client = None


@functools.lru_cache(maxsize=1)
def _string_opts_kwarg() -> str:
"""The name the installed pymongocrypt gives the string index options.

pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and accepts
only one name per release. The rename landed on master before any release
carried it, so resolve the name from the installed signature rather than
from a version comparison. Resolved lazily and cached because importing
:mod:`inspect` is too expensive to do on the import path.
"""
import inspect

params = inspect.signature(AsyncExplicitEncrypter.encrypt).parameters
return "string_opts" if "string_opts" in params else "text_opts"


def _resolve_string_opts(
string_opts: StringOpts | None, text_opts: StringOpts | None
) -> StringOpts | None:
"""Resolve string_opts and its former name, text_opts.

pymongocrypt accepts only one of the two names per release, so passing the
name the installed pymongocrypt does not support is an error.
"""
if string_opts is not None and text_opts is not None:
raise ConfigurationError("Cannot set both string_opts and text_opts")
if string_opts is None and text_opts is None:
return None
if text_opts is not None and _string_opts_kwarg() == "string_opts":
raise ConfigurationError(
"text_opts is not supported by the installed pymongocrypt "
"(1.19 or later). Use string_opts instead."
)
if string_opts is not None and _string_opts_kwarg() == "text_opts":
raise ConfigurationError(
"string_opts requires pymongocrypt 1.19 or later. Use text_opts "
"with the installed pymongocrypt, or upgrade pymongocrypt."
)
return string_opts if string_opts is not None else text_opts


class AsyncClientEncryption(Generic[_DocumentType]):
"""Explicit client-side field level encryption."""

Expand Down Expand Up @@ -892,7 +847,7 @@ async def _encrypt_helper(
contention_factor=contention_factor,
range_opts=range_opts_bytes,
is_expression=is_expression,
**({_string_opts_kwarg(): string_opts_bytes} if string_opts_bytes else {}),
string_opts=string_opts_bytes,
)
return decode(encrypted_doc)["v"]

Expand All @@ -906,7 +861,6 @@ async def encrypt(
contention_factor: int | None = None,
range_opts: RangeOpts | None = None,
string_opts: StringOpts | None = None,
text_opts: StringOpts | None = None,
) -> Binary:
"""Encrypt a BSON value with a given key and algorithm.

Expand All @@ -929,13 +883,12 @@ async def encrypt(
:class:`RangeOpts` for some valid options.
:param string_opts: Index options for `prefix`, `suffix`, and
`substring` queries. See :class:`StringOpts` for some valid options.
:param text_opts: **DEPRECATED** - The former name of `string_opts`,
added in pymongocrypt 1.16 and accepted only through pymongocrypt
1.18. Passing it to pymongocrypt 1.19 or later, or passing both
names, raises :exc:`~pymongo.errors.ConfigurationError`.

:return: The encrypted value, a :class:`~bson.binary.Binary` with subtype 6.

.. versionchanged:: 4.20
Removed the `text_opts` parameter.

.. versionchanged:: 4.18
Added the `string_opts` parameter, replacing the deprecated
`text_opts`.
Expand Down Expand Up @@ -963,7 +916,7 @@ async def encrypt(
contention_factor=contention_factor,
range_opts=range_opts,
is_expression=False,
string_opts=_resolve_string_opts(string_opts, text_opts),
string_opts=string_opts,
),
)

Expand Down
28 changes: 0 additions & 28 deletions pymongo/encryption_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from __future__ import annotations

import warnings
from collections.abc import Callable, Mapping
from typing import TYPE_CHECKING, Any, TypedDict

Expand Down Expand Up @@ -357,7 +356,6 @@ def __init__(
:param diacritic_sensitive: Whether string indexes for this field are diacritic sensitive.

.. versionadded:: 4.18
``StringOpts`` replaces ``TextOpts``, which is deprecated.
"""
self.substring = substring
self.prefix = prefix
Expand Down Expand Up @@ -416,29 +414,3 @@ class SuffixOpts(TypedDict):
strMinQueryLength: int
# strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error.
strMaxQueryLength: int


class TextOpts(StringOpts):
"""**DEPRECATED** Options to configure encrypted queries using the text algorithm.

.. note:: ``TextOpts`` is deprecated. Use :class:`StringOpts` instead.
``TextOpts`` corresponds to the ``text_opts`` parameter of
:meth:`~pymongo.encryption.ClientEncryption.encrypt`, which pymongocrypt
added in 1.16 and renamed to ``string_opts`` in 1.19. Passing
``TextOpts`` as ``text_opts`` therefore only works with pymongocrypt
1.16 through 1.18; with pymongocrypt 1.19 or later, pass
:class:`StringOpts` as ``string_opts``.

.. versionadded:: 4.15

.. versionchanged:: 4.18
Deprecated in favor of :class:`StringOpts`.
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
warnings.warn(
"TextOpts is deprecated. Use StringOpts instead.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(*args, **kwargs)
Loading
Loading