Skip to content
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

DeprecationWarning: FieldValidationInfo is deprecated #191

Closed
arjenzorgdoc opened this issue Dec 6, 2023 · 3 comments
Closed

DeprecationWarning: FieldValidationInfo is deprecated #191

arjenzorgdoc opened this issue Dec 6, 2023 · 3 comments
Labels
pydantic v2 Issues related to being between Pydantic v1 and v2

Comments

@arjenzorgdoc
Copy link

When running with -W err webauthn raises a DeprecationWarning:

~/test $ python3 -m venv .venv
~/test $ . ./.venv/bin/activate
(.venv) ~/test $ pip install webauthn
...snip...
Successfully installed annotated-types-0.6.0 asn1crypto-1.5.1 cbor2-5.5.1 cffi-1.16.0 cryptography-41.0.7 pyOpenSSL-23.3.0 pycparser-2.21 pydantic-2.5.2 pydantic-core-2.14.5 typing-extensions-4.8.0 webauthn-1.11.1
(.venv) ~/test $ python -W err -c 'import webauthn'
Traceback (most recent call last):
...snip...
  File ".../.venv/lib/python3.11/site-packages/webauthn/helpers/structs.py", line 6, in <module>
    from pydantic import (  # type: ignore[attr-defined]
...snip...
DeprecationWarning: `FieldValidationInfo` is deprecated, use `ValidationInfo` instead.
(.venv) ~/test $ 
@arjenzorgdoc
Copy link
Author

diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml
index afed84b..11abcc4 100644
--- a/.github/workflows/build_and_test.yml
+++ b/.github/workflows/build_and_test.yml
@@ -31,7 +31,7 @@ jobs:
         pip install 'pydantic${{ matrix.pydantic-version }}'
     - name: Test with unittest
       run: |
-        python -m unittest
+        python -W err -m unittest
     - name: Run mypy
       run: |
         python -m mypy webauthn
diff --git a/webauthn/helpers/structs.py b/webauthn/helpers/structs.py
index 5bada95..1542b8d 100644
--- a/webauthn/helpers/structs.py
+++ b/webauthn/helpers/structs.py
@@ -7,7 +7,7 @@ try:
         BaseModel,
         field_validator,
         ConfigDict,
-        FieldValidationInfo,
+        ValidationInfo,
         model_serializer,
     )
 
@@ -66,24 +66,9 @@ class WebAuthnBaseModel(BaseModel):
 
         @field_validator("*", mode="before")
         def _pydantic_v2_validate_bytes_fields(
-            cls, v: Any, info: FieldValidationInfo  # type: ignore[valid-type]
+            cls, v: Any, info: ValidationInfo
         ) -> Any:
-            """
-            `FieldValidationInfo` above is being deprecated for `ValidationInfo`, see the following:
-
-            - https://github.com/pydantic/pydantic-core/issues/994
-            - https://github.com/pydantic/pydantic/issues/7667
-
-            There are now docs for the new way to access `field_name` that's only available in
-            Pydantic v2.4+...
-
-            https://docs.pydantic.dev/latest/concepts/types/#access-to-field-name
-
-            This use of `FieldValidationInfo` will continue to work for now, but when it gets
-            removed from Pydantic the `info.field_name` below will need to get updated to
-            `info.data.field_name` after changing the type of `info` above to `ValidationInfo`
-            """
-            field = cls.model_fields[info.field_name]  # type: ignore[attr-defined]
+            field = cls.model_fields[info.field_name]  # type: ignore[index]
 
             if field.annotation != bytes:
                 return v

@MasterKale
Copy link
Collaborator

This will end up getting closed out if/when I move forward with #195.

@MasterKale
Copy link
Collaborator

I've merged #195 which removed Pydantic as a dependency of this project so I'm closing out any PR's and issues related to Pydantic as they're no longer needed.

@MasterKale MasterKale closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2024
@MasterKale MasterKale added the pydantic v2 Issues related to being between Pydantic v1 and v2 label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pydantic v2 Issues related to being between Pydantic v1 and v2
Projects
None yet
Development

No branches or pull requests

2 participants