redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.06k stars 108 forks source link

AnyUrl & HttpUrl validation error #571

Closed rglKali closed 2 months ago

rglKali commented 8 months ago

OS: Ubuntu 22.04.3 LTS (WSL2)

Python: 3.11.6

Redis: 7.2.2

Code sample:

from pydantic import HttpUrl, BaseModel
from redis_om import JsonModel

class Crush(BaseModel):
    http: HttpUrl

class Test(JsonModel):
    http: HttpUrl

Shell test:

kali@rglKali:~/$ python
Python 3.11.6 (main, Oct 17 2023, 16:29:19) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from test import Crush, Test
>>> Crush(http='https://avatars.githubusercontent.com/u/1529926?s=48&v=4')
Crush(http=Url('https://avatars.githubusercontent.com/u/1529926?s=48&v=4'))
>>> Test(http='https://avatars.githubusercontent.com/u/1529926?s=48&v=4')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kali/venv/lib/python3.11/site-packages/redis_om/model/model.py", line 1683, in __init__
    super().__init__(*args, **kwargs)
  File "/home/kali/venv/lib/python3.11/site-packages/redis_om/model/model.py", line 1295, in __init__
    super().__init__(**data)
  File "/home/kali/venv/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for Test
http
  instance of Url expected (type=type_error.arbitrary_type; expected_arbitrary_type=Url)