You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can't save a model with a field of type pydantic.AnyUrl.
Current Behavior
from odmantic import Model
from pydantic import AnyUrl
from api.models import db
class User(Model):
name: str
class UserWithPicture(Model):
name: str
picture: AnyUrl
async def test_urls() -> None:
# saves user as expected
user = User(name="tom")
await db.save(user)
# add a url and it throws an error
user_with_picture = UserWithPicture(
name="harry",
picture="https://picsum.photos/200/300",
)
await db.save(user_with_picture)
if __name__ == "__main__":
import asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(test_urls())
Output:
bson.errors.InvalidDocument: cannot encode object: Url('https://picsum.photos/200/300'), of type: <class 'pydantic_core._pydantic_core.Url'>
Expected behavior
I'm upgrading from pydantic v1/odmantic 0.8.0 to pydantic v2/odmantic 1.0.2. Saving urls was working before the upgrade, and I'd expect it to continue working.
Environment
ODMantic version: 1.0.2
MongoDB version: 6
Pydantic infos (output of python -c "import pydantic.utils; print(pydantic.utils.version_info())):
Bug
Can't save a model with a field of type
pydantic.AnyUrl
.Current Behavior
Output:
Expected behavior
I'm upgrading from
pydantic v1
/odmantic 0.8.0
topydantic v2
/odmantic 1.0.2
. Saving urls was working before the upgrade, and I'd expect it to continue working.Environment
python -c "import pydantic.utils; print(pydantic.utils.version_info())
):The text was updated successfully, but these errors were encountered: