fix(warnings): give the User-Agent override warning a stacklevel (#1363)

`show_warning_once` defaults to `stacklevel=1`, which makes `warnings.warn`
attribute the warning to `qdrant_client/common/client_warnings.py:7` -- inside
the client -- instead of the caller's construction site.

Every other `show_warning_once` call in the package passes an explicit
stacklevel (4, 5, 6 or 10, depending on nesting); this is the only site that
omits it. Its two immediate siblings in the same `__init__` -- the
`api-key`-in-headers warning and the `grpc.primary_user_agent` warning -- both
pass `stacklevel=4`, so this brings it in line with them.

Before:
  .../qdrant_client/common/client_warnings.py:7: UserWarning: `User-Agent` ...
After:
  .../qdrant_client/qdrant_client.py:134: UserWarning: `User-Agent` ...

which is where the sibling warnings already point.

`async_qdrant_remote.py` is generated from the sync source; the hunk there
matches what `tools/generate_async_client.sh` emits (verified by running the
generator with ruff pinned to 0.4.3).
This commit is contained in:
Tai An
2026-09-16 00:25:21 +07:00
committed by George Panchuk
parent 9343494232
commit 704f037e8a
2 changed files with 7 additions and 3 deletions
+3 -1
View File
@@ -145,7 +145,9 @@ class AsyncQdrantRemote(AsyncQdrantBase):
user_agent = f"python-client/{client_version} python/{python_version}"
if "User-Agent" in self._rest_headers:
show_warning_once(
f"`User-Agent` has been passed in `headers`, but it will be overridden with the builtin value: `{user_agent}`."
message=f"`User-Agent` has been passed in `headers`, but it will be overridden with the builtin value: `{user_agent}`.",
category=UserWarning,
stacklevel=4,
)
if grpc_options is not None and "grpc.primary_user_agent" in grpc_options:
show_warning_once(
+4 -2
View File
@@ -178,8 +178,10 @@ class QdrantRemote(QdrantBase):
user_agent = f"python-client/{client_version} python/{python_version}"
if "User-Agent" in self._rest_headers:
show_warning_once(
"`User-Agent` has been passed in `headers`, but "
f"it will be overridden with the builtin value: `{user_agent}`."
message="`User-Agent` has been passed in `headers`, but "
f"it will be overridden with the builtin value: `{user_agent}`.",
category=UserWarning,
stacklevel=4,
)
if grpc_options is not None and "grpc.primary_user_agent" in grpc_options: