sopherapps / pydantic-redis

A simple Declarative ORM for Redis using pydantic Models
https://sopherapps.github.io/pydantic-redis
MIT License
39 stars 14 forks source link

if no results, expecting an empty list #38

Open wasperen2 opened 2 months ago

wasperen2 commented 2 months ago

Describe the bug When doing a .select(ids=[...]), for an _id that does not exist, one would expect an empty list rather than None

To Reproduce

import uuid
from typing import Optional

from pydantic import Field
from pydantic_redis import Store, RedisConfig, Model

class SomeModel(Model):
    _primary_key_field = "id"
    id: str = Field(
        default_factory=lambda: uuid.uuid4().hex,
    )
    name: str = Field()

store = Store(
    name="none should return a list too",
    redis_config=RedisConfig(host='localhost', port=6379, db=6)
)

store.register_model(SomeModel)

parent = SomeModel(name="bong bing")

SomeModel.insert(parent)

models_received = SomeModel.select(ids=["some none existing id"])
print(models_received)
assert isinstance(models_received, list)

Expected behavior One would expect this assertion to pass. Instead, we get:

    assert isinstance(models_received, list)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
None
wasperen2 commented 2 months ago

If columns is specified, the select method does return an empty list