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

Error is thrown with Pydantic PositiveInt and index=True fields #590

Closed
i-arindam opened this issue Jan 29, 2024 · 1 comment · Fixed by #603
Closed

Error is thrown with Pydantic PositiveInt and index=True fields #590

i-arindam opened this issue Jan 29, 2024 · 1 comment · Fixed by #603

Comments

@i-arindam
Copy link

If i have a JsonModel with a field that has pydantic's PositiveInt as the type, i am not able to use index=True in the field setting. Given a simple model

from redis_om import JsonModel, Field
from pydantic import PositiveInt

class JModel(JsonModel):
    age: PositiveInt = Field(index=True) 

when i try to import this in my django project's shell, i get the following errors

>>> from path.to.model.jmodel import Jmodel
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/arindam.chakraborty/Documents/projects/algo_trading/algo_trading/models/live_order_manager/models/check_jmodel.py", line 4, in <module>
    class JModel(JsonModel):
  File "/Users/arindam.chakraborty/Documents/projects/algo_trading/venv/lib/python3.9/site-packages/redis_om/model/model.py", line 1195, in __new__
    new_class = super().__new__(cls, name, bases, attrs, **kwargs)
  File "/Users/arindam.chakraborty/Documents/projects/algo_trading/venv/lib/python3.9/site-packages/pydantic/v1/main.py", line 282, in __new__
    cls = super().__new__(mcs, name, bases, new_namespace, **kwargs)
  File "/usr/local/Cellar/[email protected]/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/abc.py", line 106, in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
  File "/Users/arindam.chakraborty/Documents/projects/algo_trading/venv/lib/python3.9/site-packages/redis_om/model/model.py", line 1675, in __init_subclass__
    cls.redisearch_schema()
  File "/Users/arindam.chakraborty/Documents/projects/algo_trading/venv/lib/python3.9/site-packages/redis_om/model/model.py", line 1742, in redisearch_schema
    schema_parts = [schema_prefix] + cls.schema_for_fields()
  File "/Users/arindam.chakraborty/Documents/projects/algo_trading/venv/lib/python3.9/site-packages/redis_om/model/model.py", line 1753, in schema_for_fields
    cls.schema_for_type(json_path, name, "", _type, field.field_info)
  File "/Users/arindam.chakraborty/Documents/projects/algo_trading/venv/lib/python3.9/site-packages/redis_om/model/model.py", line 1890, in schema_for_type
    elif any(issubclass(typ, t) for t in NUMERIC_TYPES):
  File "/Users/arindam.chakraborty/Documents/projects/algo_trading/venv/lib/python3.9/site-packages/redis_om/model/model.py", line 1890, in <genexpr>
    elif any(issubclass(typ, t) for t in NUMERIC_TYPES):
TypeError: issubclass() arg 1 must be a class

If I change the type to either int or str the import works fine.

@slorello89
Copy link
Member

This should be fixed by #603

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.

2 participants