-
Notifications
You must be signed in to change notification settings - Fork 13
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
⬆️ Upgrade pydantic to v2 #72
Conversation
e8677ef
to
cc0f2b5
Compare
0431839
to
984f262
Compare
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
…ecessary. See https://docs.pydantic.dev/2.2/migration/#changes-to-pydanticgenericsgenericmodel Signed-off-by: ff137 <ff137@proton.me>
…ator` See https://docs.pydantic.dev/2.2/migration/#changes-to-validators Signed-off-by: ff137 <ff137@proton.me>
See https://docs.pydantic.dev/2.2/migration/#changes-to-config Signed-off-by: ff137 <ff137@proton.me>
…ew `__get_pydantic_core_schema__` and `__get_pydantic_json_schema__` See https://docs.pydantic.dev/2.2/migration/#defining-custom-types Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
…ump_json` Signed-off-by: ff137 <ff137@proton.me>
…s. Replaces deprecated `parse_obj_as`. See https://docs.pydantic.dev/2.2/migration/#introduction-of-typeadapter Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
… Use pydantic's alias generator instead of relying on `inflection.camelize`. See https://docs.pydantic.dev/2.2/migration/#changes-to-config Signed-off-by: ff137 <ff137@proton.me>
…dantic changes Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
…to help the compiler Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
…g to a set of possible types is not possible. Or not straightforward enough for me (sorry) Signed-off-by: ff137 <ff137@proton.me>
… camel case or snake case Signed-off-by: ff137 <ff137@proton.me>
@dbluhm I think I have done it 👀 Just as I was nearing the end of my rope, with 50 tests failing because DIDDocuments couldn't serialize ... when all seemed lost, I realised that for the new pydantic I'll spare most of the detail, but basically you don't want the "after" validators (
(because some of the existing validator logic wants to iterate over That was the breakthrough that solved all the DIDDocuments not being able to serialize, and then there were just a handful of test failures that could more easily be traced down. That initial breakthrough did take a lot of persistence though, with many hours of head scratching. There were quite a few places where I just guessed what's the best solution -- so please do review thoroughly!
|
…fact work Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
As luck would have it, the 1.74% of uncovered code seems to contain a bug! Investigating |
38efd3f
to
1ec56b2
Compare
Well, I'm not quite sure why, but Pydantic is complaining about a v1 method being used: File "/home/aries/.local/lib/python3.9/site-packages/pydid/service.py", line 16, in <module>
class Service(Resource):
File "/usr/local/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 202, in __new__
complete_model_class(
...
File "/usr/local/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 1804, in inner_handler
metadata_js_function = _extract_get_pydantic_json_schema(obj, schema)
File "/usr/local/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 2157, in _extract_get_pydantic_json_schema
raise PydanticUserError(
pydantic.errors.PydanticUserError: The `__modify_schema__` method is not supported in Pydantic v2. Use `__get_pydantic_json_schema__` instead in class `DIDUrl`. The error appears to be misleading, because we do not have def _extract_get_pydantic_json_schema(tp: Any, schema: CoreSchema) -> GetJsonSchemaFunction | None:
"""Extract `__get_pydantic_json_schema__` from a type, handling the deprecated `__modify_schema__`."""
js_modify_function = getattr(tp, '__get_pydantic_json_schema__', None)
if hasattr(tp, '__modify_schema__'):
from pydantic import BaseModel # circular reference
has_custom_v2_modify_js_func = (
js_modify_function is not None
and BaseModel.__get_pydantic_json_schema__.__func__ # type: ignore
not in (js_modify_function, getattr(js_modify_function, '__func__', None))
)
if not has_custom_v2_modify_js_func:
cls_name = getattr(tp, '__name__', None)
raise PydanticUserError(
f'The `__modify_schema__` method is not supported in Pydantic v2. '
f'Use `__get_pydantic_json_schema__` instead{f" in class `{cls_name}`" if cls_name else ""}.',
code='custom-json-schema',
) Well, I can't make much sense of it this late at night, but it appears I've not implemented |
The above error was indeed misleading. Very bizarre, but it appears to be that pydid and pydantic versions got mixed up in dependency tree for where I was testing. |
Signed-off-by: ff137 <ff137@proton.me>
Signed-off-by: ff137 <ff137@proton.me>
@dbluhm good stuff! All checks have passed in openwallet-foundation/acapy#2919 |
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.
Finally got around to reviewing, thanks for your patience! Changes look good. Glad to have this update taken care of! Thanks again!
Some minor conflicts to poetry lock after I merged in dependabot PRs |
Signed-off-by: ff137 <ff137@proton.me>
lock file updated 👍 |
@dbluhm the following lines:
Is there a new Service type that needs to be added to that |
Good question. I think the behavior in 1.x of pydantic was happy to consider Service to be an UnknownService. It seems 2.x is pickier. We might be able to get the same functionality by just using |
🚧 work in progress - converted all the basic, deprecated methods, with the help of bump-pydantic
Currently struggling to get deserialization to work. Will update with progress soon