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

Optional[int] raise error if missing #261

Open
dusking opened this issue May 23, 2022 · 2 comments
Open

Optional[int] raise error if missing #261

dusking opened this issue May 23, 2022 · 2 comments

Comments

@dusking
Copy link

dusking commented May 23, 2022

If I have a model with the following field:
number: Optional[int]

I can create a record without the number. But, when I'll call model.get(pk) - I'll get an error:
value is not a valid integer (type=type_error.integer)

@dusking dusking changed the title Optional[int[ raise error if missing Optional[int] raise error if missing May 23, 2022
@msarm
Copy link

msarm commented Jun 18, 2022

Just to be clear, this issue exist for other data types as well (like datetime, float, etc).

Here sample code to replicate this issue:

import datetime
from datetime import datetime
from typing import Optional

from redis_om import Field, HashModel, Migrator, get_redis_connection

# This Redis instance is tuned for durability.
REDIS_DATA_URL = "redis://localhost:6379"

class Person(HashModel):
    first_name: str = Field(index=True)
    last_name: str = Field(index=True)
    emp_no: int =  Field(index=True, sortable=True)
    lastDate: Optional[datetime]
    dailyWage: Optional[float]
    workDayPerWeek: Optional[int]

# set redis connection
Person.Meta.database = get_redis_connection(url=REDIS_DATA_URL,
                                                  decode_responses=True)
# apply migrations
Migrator().run()


# add employe
emp_no = 999
person = Person(first_name="John" + str(emp_no), last_name="Doe", emp_no=emp_no)
person.save()
    
# get employee
result = Person.find().all()

@sav-norem
Copy link
Contributor

This is being worked on - but in the meantime if you can, this issue only applies to HashModels and you can swap it for a JsonModel and it will work

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

No branches or pull requests

3 participants