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

Fix None instance when querying #368

Merged
merged 1 commit into from
Sep 8, 2022
Merged

Fix None instance when querying #368

merged 1 commit into from
Sep 8, 2022

Conversation

tonibofarull
Copy link
Contributor

Context
I have an application that is constantly adding instance into redis with a TTL and another application that reads queries it.

Bug
Sometimes, the application that queries gets the following error:

  File "/home/worker/.local/lib/python3.10/site-packages/aredis_om/model/model.py", line 760, in all
    return await query.execute()
  File "/home/worker/.local/lib/python3.10/site-packages/aredis_om/model/model.py", line 727, in execute
    results = self.model.from_redis(raw_result)
  File "/home/worker/.local/lib/python3.10/site-packages/aredis_om/model/model.py", line 1204, in from_redis
    map(to_string, res[i + fields_offset][::2]),
TypeError: 'NoneType' object is not subscriptable

If this application queries again, the error disappear for a while.

Reason (?)
I think that the main problem is the interaction between the TTL and the query. If I examine the res variable in this loop:

for i in range(1, len(res), step):
fields = dict(
zip(
map(to_string, res[i + offset][::2]),
map(to_string, res[i + offset][1::2]),
)
)
# $ means a json entry
if fields.get("$"):
json_fields = json.loads(fields.pop("$"))
doc = cls(**json_fields)
else:
doc = cls(**fields)
docs.append(doc)
return docs

I see that the reason of the exception is that the variable has the following structure:

[
    3,
    ':src.model.MySchema:01GBZF2X6NZZQQ8M519J9B0NR9', None,
    ':src.model.MySchema:01GBZF2XSF7EKFB3AEA6EW85P2', ['instance_id', 'e86a35a9-0d5f-409c-a1ca-0d84832d2585', 'status', 'success'],
    ':src.model.MySchema:01GBZF2WHPNDE1K917NJ6TBV5N', ['instance_id', '9f61a920-cc58-4fdc-93c8-6bba872c4132', 'status', 'success'],
]

which means trying to access a position in a None.

I'm assuming that the reason of having a None is because the instance has died in the redis database but the key is still in the redis index.

@tonibofarull
Copy link
Contributor Author

Hi @dvora-h and @chayim, can anyone review this PR? 🙇‍♂️
Another question. When is it planned to release a new version in pypi? The last one was 3 months ago.

@dvora-h dvora-h added the bug Something isn't working label Sep 8, 2022
@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2022

Codecov Report

Merging #368 (3ece203) into main (788d3df) will decrease coverage by 0.04%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##             main     #368      +/-   ##
==========================================
- Coverage   77.64%   77.59%   -0.05%     
==========================================
  Files          14       14              
  Lines        1154     1156       +2     
==========================================
+ Hits          896      897       +1     
- Misses        258      259       +1     
Flag Coverage Δ
unit 77.59% <50.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aredis_om/model/model.py 86.42% <50.00%> (-0.09%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dvora-h
Copy link
Contributor

dvora-h commented Sep 8, 2022

@tonibofarull Thanks for this fix!

I think we will release a new version soon.

@dvora-h dvora-h merged commit 9e17678 into redis:main Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants