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

typing.Dict cannot be used as a JsonModel field #613

Closed
woutdenolf opened this issue May 4, 2024 · 0 comments · Fixed by #614
Closed

typing.Dict cannot be used as a JsonModel field #613

woutdenolf opened this issue May 4, 2024 · 0 comments · Fixed by #614

Comments

@woutdenolf
Copy link

Python            3.9.18

hiredis           2.3.2
redis             5.0.4
redis-om          0.3.0
types-redis       4.6.0.20240425

pydantic          2.7.1
pydantic_core     2.18.2

This causes the exception

from typing import Dict
from redis_om import JsonModel


class ScanModel(JsonModel):
    info: Dict
Traceback (most recent call last):
  File "/home/denolf/tmp/blissdata.py", line 5, in <module>
    class ScanModel(JsonModel):
  File "/home/denolf/virtualenvs/pybox_rAqscR/lib/python3.9/site-packages/redis_om/model/model.py", line 1250, in __new__
    new_class = super().__new__(cls, name, bases, attrs, **kwargs)
  File "/home/denolf/virtualenvs/pybox_rAqscR/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 115, in __new__
    cls: type[BaseModel] = super().__new__(mcs, cls_name, bases, namespace, **kwargs)  # type: ignore
  File "/home/denolf/.pyenv/versions/3.9.18/lib/python3.9/abc.py", line 106, in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
  File "/home/denolf/virtualenvs/pybox_rAqscR/lib/python3.9/site-packages/redis_om/model/model.py", line 1813, in __init_subclass__
    cls.redisearch_schema()
  File "/home/denolf/virtualenvs/pybox_rAqscR/lib/python3.9/site-packages/redis_om/model/model.py", line 1882, in redisearch_schema
    schema_parts = [schema_prefix] + cls.schema_for_fields()
  File "/home/denolf/virtualenvs/pybox_rAqscR/lib/python3.9/site-packages/redis_om/model/model.py", line 1903, in schema_for_fields
    _type = get_outer_type(field)
  File "/home/denolf/virtualenvs/pybox_rAqscR/lib/python3.9/site-packages/redis_om/model/model.py", line 86, in get_outer_type
    return field.annotation.__args__[0]
  File "/home/denolf/.pyenv/versions/3.9.18/lib/python3.9/typing.py", line 711, in __getattr__
    raise AttributeError(attr)
AttributeError: __args__

The issue does not occur with "pip install redis-om<0.3"

Python            3.9.18

hiredis           2.3.2
redis             5.0.4
redis-om          0.2.2
types-redis       4.6.0.20240425

pydantic          2.4.2
pydantic_core     2.10.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant