redis / redis/redis-om-python

Redis-om model randomly returns NotFoundError

Open
#648 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug more info needed
Dominant language
Python
Stars
1.3k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

The model below, with indexed fields, as pasted below, returns data without issues in 13 cases and fails 2, running the same 15 unit tests core function to retrieve the object from Redis. In to cases, however, it fails to pull data with no apparent reason; The workaround added to find ALL entries when catching exception works, but the same behavior is observed in multiple other places with different models, all related to the same query.

The environmental variables and the name parameter are the same for all tests, but it only fails on 2 runs of the same function.
It also fails to find the object in related Python debugger console attached at breakpoint.

Model definition:

class PlatformR(JsonModel):
    """DDI Platform representation."""

    model_config = ConfigDict(
        strict=False,
    )

    id: str = RedisField(index=True)
    name: str = RedisField(index=True)

    hostname: str = RedisField(index=True)
    company: str = RedisField(index=True)
    api_version: Optional[str] = None
    credentials: Optional[PlatformCredentials] = None

Lookup function

    def get_hostname_by_name(self, ddi_platform: str) -> str:
        """Get hostname by platform name."""
        logging.debug("Get hostname by platform name")
        try:
            return (
                PlatformR.find(PlatformR.name == ddi_platform).first().hostname
            )
        except NotFoundError:
            logging.error(f"Platform {ddi_platform} not found")
            ### Workaround - find all object, filter manually by Python iteration
            for platform in PlatformR.find().all(): 
                if platform.name == ddi_platform:
                    return platform.hostname
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail=f"Platform {ddi_platform} not found",
            )

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 with the PlatformR.find(PlatformR.name == ddi_platform).first() lookup and compare it with the shown PlatformR.find().all() workaround. Reproduce the 15-test pattern and inspect the indexed name query; done means identifying the cause of intermittent NotFoundError and covering the behavior with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, redis
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.