-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #2832: Add protected_namespaces to Config class within utils.py, router.py and completion.py to avoid the warning message. #2893
Conversation
…in utils.py, router.py and completion.py to avoid the warning message.
…nother to Config class within the router.py
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm ! @unclecode do you have suggestions on how we can avoid this warning in the future
is this going to be in 1.34.38? ETA for release? |
ETA is latest by EOD today |
Awesome, Thank you! |
Maybe a simple CI check making sure |
@ishaan-jaff Since version 2, Pydantic added model_ to their protected namespace, a common term in ML. One workaround is adding However there is one funny hack. Alternatively, you can intercept the global log in Python to bypass this message. Here’s a sample for you: import warnings
import logging
def custom_warning_handler(message, category, filename, lineno, file=None, line=None):
# Check the warning message or category here
if 'Field "model_name" has conflict with protected namespace' in str(message):
pass
else:
original_showwarning(message, category, filename, lineno, file, line)
# Save a reference to the original showwarning function
original_showwarning = warnings.showwarning
# Override the showwarning function with your custom handler
warnings.showwarning = custom_warning_handler
## ===================================
from pydantic import BaseModel
from typing import Optional
from pydantic.fields import Field
class Device(BaseModel):
model_name: Optional[str] = Field(None)
data = {
'model_name': "ab",
}
m = Device(**data)
print(m) It's like instead of cleaning your room, you just shove all the trash under the bed 😄. I know it's lame, but hey, it works! |
I still see an issue on main-v1.35.31. Is this related?
|
I will start to try to fix following errors in current ../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:219
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:219: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:306
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:306: PydanticDeprecatedSince20: `pydantic.config.Extra` is deprecated, use literal values instead (e.g. `extra='allow'`). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
extra = Extra.allow # Allow extra fields
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:309
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:309: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:338
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:338: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:385
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:385: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:451
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:451: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:463
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:463: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:503
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:503: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:537
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:537: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:828
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:828: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:855
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:855: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True)
../../../.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:874
/home/runner/.cache/pypoetry/virtualenvs/opendevin-cQohdhQS-py3.11/lib/python3.11/site-packages/litellm/proxy/_types.py:874: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/
@root_validator(pre=True) |
Fixes #2832
Problem
The library was using Pydantic, and some of its models had attribute names that conflicted with Pydantic's protected namespaces. This caused warning messages to be generated when using these models. The affected files were:
types/router.py
types/completion.py
utils.py
Solution
To resolve the namespace conflicts and suppress the warning messages, I added a configuration to the affected models to disable Pydantic's namespace protection for these specific models. This allows the use of attribute names that conflict with the protected namespaces without triggering warnings.
By setting
protected_namespaces
to an empty tuple()
, Pydantic's namespace protection is disabled for these specific models. This allows the use of attribute names that conflict with the protected namespaces without triggering warnings.The changes were made in the following files:
types/router.py
types/completion.py
utils.py
Testing
To ensure that the changes resolved the issue, I ran the affected code and verified that no warning messages related to Pydantic namespace conflicts were generated.
Additional Notes
Disabling the namespace protection should be done with caution, as it may potentially lead to naming conflicts if attribute names unintentionally match the protected namespaces. However, in this case, the attribute names causing the conflicts were intentional and necessary for the library's functionality.
Please let me know if you have any questions or feedback regarding this pull request. Thank you for considering this contribution!