Repository: huggingface/text-generation-inference
Pull request: corrected Pydantic warning.
On using python client with pydantic 2, it raises a warning on import time: 
this corners of the execution logs

Fixes #1761

- [ ] I ran it locally with the patch 


@OlivierDehaene 
@Narsil

Problem statement:
Importing from `text_generation.errors` throws Pydantic warning.
### System Info

Using `text-generation` python package version `0.7.0`, importing from the `errors` submodule throws a warning for protected namespace due to `model` being a protected namespace and the existence of the `model_id` field in `NotSupportedError`.

```
/home/chris/Code/venv/lib/python3.12/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_id" has conflict with protected namespace "model_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
```

```
# Suppress Pydantic protected namespace warnings from text_generation package to avoid cluttering logs
with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=UserWarning)
    from text_generation.errors import RateLimitExceededError, OverloadedError
```
Is my current workaround.

### Information

- [ ] Docker
- [ ] The CLI directly

### Tasks

- [ ] An officially supported command
- [X] My own modifications

### Reproduction

1. import from `text_generation.errors` in a python application.

### Expected behavior

The ConfigDict for Pydantic prevents the warning from being logged out, or the field is changed to a non-protected namespace.

Hints from issue discussion:
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Commit message: corrected Pydantic warning.

Patch to review:
diff --git a/clients/python/text_generation/types.py b/clients/python/text_generation/types.py
index eb872ee6564..92f229ce986 100644
--- a/clients/python/text_generation/types.py
+++ b/clients/python/text_generation/types.py
@@ -1,5 +1,5 @@
 from enum import Enum
-from pydantic import BaseModel, field_validator
+from pydantic import BaseModel, field_validator, ConfigDict
 from typing import Optional, List, Union, Any
 
 from text_generation.errors import ValidationError
@@ -452,5 +452,6 @@ class StreamResponse(BaseModel):
 
 # Inference API currently deployed model
 class DeployedModel(BaseModel):
+    model_config  = ConfigDict(protected_namespaces=())
     model_id: str
     sha: str


Code review comments:
diff_hunk: @@ -452,5 +452,6 @@ class StreamResponse(BaseModel):
 
 # Inference API currently deployed model
 class DeployedModel(BaseModel):
+    model_config  = ConfigDict(protected_namespaces=())
path: clients/python/text_generation/types.py
text: @user1:
```suggestion
    # Disable warning for use of `model_` prefix in `model_id`. Be mindful about adding members
    # with model_ prefixes, since this disables guardrails for colliding fields:
    # https://github.com/pydantic/pydantic/issues/9177
    model_config  = ConfigDict(protected_namespaces=())
```

@author:
Sounds like a good idea