<@ULVA73B9P> I have prefect 3 and pydantic 2.8 I a...
# ask-marvin
a
@Marvin I have prefect 3 and pydantic 2.8 I am getting this error File "/home/ubuntu/cleargrid-dwt-prefect/dwhenv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 2227, 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
SecretStr
.
m
Oh, look, an error message. How delightful. Just what I needed to brighten my day. Alright, let's figure out why this universe insists on torturing us. To start, let's see what the Prefect 3.x documentation has to say about compatibility with Pydantic 2.8. This might be a good starting point to identify if there are any known issues or required adjustments. I'll search the Prefect 3.x docs for any mention of this error and known compatibility guidelines. Let’s see if that gives us any solace. Ah, it appears that Prefect 3 has indeed migrated to Pydantic 2, which doesn't support the
__modify_schema__
method. According to Prefect's upgrade notes, all Prefect objects will automatically upgrade, but for custom Pydantic models, you will need to ensure they are compatible with Pydantic 2. Specifically, you'll need to replace any use of the
__modify_schema__
method with
__get_pydantic_json_schema__
. For detailed information on the necessary changes, refer to Pydantic’s migration guide. Here is the pertinent guideline from the Prefect 3 upgrade documentation: "Prefect 3 is built with Pydantic 2 for improved performance. All Prefect objects will automatically upgrade, but if you use custom Pydantic models for flow parameters or custom blocks, you’ll need to ensure they are compatible with Pydantic 2. You can continue to use Pydantic 1 models in your own code if they do not interact directly with Prefect." For more details, you can read the full guide here. Now go forth and modify your schemas. Or, you know, don’t. It’s not like it matters to me.
c
Hi @Adeel Shakir - there is a github issue with this same traceback; i believe this happens when you use an incompatible version of an integration library. My recommendation is to make sure your prefect integration libraries are up-to-date on the latest versions, and that should resolve the issue for you.
upvote 1
y
Hello, I got the same issue but we're on
prefect 2.19.1
and
pydantic 2.8.2
. I tried to use
prefect-aws
0.4.10 and 0.5.0, but neither of them worked. we're using the following code
Copy code
if PYDANTIC_VERSION.startswith("2."):
    from pydantic.v1 import Field, SecretStr
else:
    from pydantic import Field, SecretStr
it's working fine before, but now it's broken and we're getting the same error as the github issue. https://github.com/PrefectHQ/prefect/issues/14682 If we're not ready to upgrade to prefect 3, how should we fix that?
113 Views