redis / redis/redis-om-python

How does one find a model with a None field value?

Open
#485 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
1.3k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

I have a model like this:

class City(JsonModel):
    country_id: str = Field(index=True)
    region_id: str | None = Field(index=True)

How do I query for a city in a specific country that is not associated with any region? I.e.: a capital or a large city like Bremen in Germany?

The following queries do not work and raise errors:

cities = City.find((City.country_id == "de") & (City.region_id is None)).all()

aioredis_om.model.model.QuerySyntaxError: Counld not resolve field name. See docs: TODO
cities = City.find((City.country_id == "de") & (City.region_id == None)).all()

TypeError: argument of type 'NoneType' is not iterable

I failed to find any reference in the docs about scenarios like that... 🤔

P.S.: SQLAlchemy has .filter(City.region_id == None) or .filter(City.region_id.is_not(None)) to handle those cases.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two City.find queries shown in the issue and trace how JsonModel field comparisons handle None, especially the country_id and region_id expression paths. The issue is done when a city can be queried by country with no region association, with the supported syntax documented and the reported errors no longer occurring.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, redis
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.