Skip to content

When using hashmodel, 'id' appears to be a reserved name? #223

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

Closed
rkulagowski opened this issue Apr 29, 2022 · 3 comments
Closed

When using hashmodel, 'id' appears to be a reserved name? #223

rkulagowski opened this issue Apr 29, 2022 · 3 comments

Comments

@rkulagowski
Copy link

from redis_om import Field, HashModel, Migrator
from pydantic import PositiveInt, ValidationError
from typing import Optional

class RatingBody(HashModel):
    id: PositiveInt = Field(index=True)
    name: str
    country: str
    language: str
    code: str
    description: Optional[str]
    update_ID: PositiveInt
    update_date: str

def lambda_handler(event, context):
    try:
        c_v = RatingBody(
            id=1,
            name='abcd',
            country='usa',
            language='en',
            code='2134',
            description='test value',
            update_ID=9876554,
            update_date='2022-04-29'
        )
        c_v.save()
    except ValidationError as e:
        print(f'validation error: {e}')
    Migrator().run()
    a = RatingBody.find(RatingBody.id == 1).all()
    print ("Breakpoint here")


if __name__ == '__main__':
    lambda_handler(None, None)
    print ("Done")

Will result in the following error:

pydantic.error_wrappers.ValidationError: 1 validation error for RatingBody
id
  field required (type=value_error.missing)

Changing from 'id' to anything else causes the code to work.

@dadwin
Copy link

dadwin commented Jul 4, 2022

It's because RedisModel.from_redis() intentionally removes id from fields, so later pyndantic validation fails:
https://github.com/redis/redis-om-python/blob/main/aredis_om/model/model.py#L1211

No clue why so far, didn't find mentions in code/docs

@wiseaidev
Copy link
Contributor

fixed in pull/337.

@sav-norem
Copy link

@simonprickett fix has been merged so we can close this out

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

5 participants