From 163c35a6143b3e7689faa9b361567d2dea10f6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Sat, 30 Apr 2022 00:08:35 +0200 Subject: [PATCH] fix: Avoid exception if bytes in query --- lookyloo/lookyloo.py | 13 ++++++++----- poetry.lock | 18 +++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index e8a6d33..06066c3 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -367,17 +367,20 @@ class Lookyloo(): for key, value in query.items(): if isinstance(value, bool): query[key] = 1 if value else 0 - if isinstance(value, (list, dict)): + elif isinstance(value, (list, dict)): query[key] = json.dumps(value) + elif isinstance(value, bytes): + query[key] = value.decode() # dirty deduplicate hash_query = hashlib.sha512(json.dumps(query).encode()).hexdigest() - perma_uuid = self.redis.get(f'query_hash:{hash_query}') - if perma_uuid: - return perma_uuid + # FIXME The line below should work, but it doesn't + # if (existing_uuid := self.redis.set(f'query_hash:{hash_query}', temp_uuid, get=True, nx=True, ex=300)): + if (existing_uuid := self.redis.get(f'query_hash:{hash_query}')): + return existing_uuid perma_uuid = str(uuid4()) - self.redis.setex(f'query_hash:{hash_query}', 300, perma_uuid) + self.redis.set(f'query_hash:{hash_query}', perma_uuid, nx=True, ex=300) priority = get_priority(source, user, authenticated) p = self.redis.pipeline() diff --git a/poetry.lock b/poetry.lock index 0acec1b..dd8441c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -452,7 +452,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [[package]] name = "ipython" -version = "8.2.0" +version = "8.3.0" description = "IPython: Productive Interactive Computing" category = "dev" optional = false @@ -1126,7 +1126,7 @@ python-versions = "*" [[package]] name = "types-requests" -version = "2.27.24" +version = "2.27.25" description = "Typing stubs for requests" category = "dev" optional = false @@ -1145,7 +1145,7 @@ python-versions = "*" [[package]] name = "types-urllib3" -version = "1.26.13" +version = "1.26.14" description = "Typing stubs for urllib3" category = "dev" optional = false @@ -1731,8 +1731,8 @@ importlib-resources = [ {file = "importlib_resources-5.7.1.tar.gz", hash = "sha256:b6062987dfc51f0fcb809187cffbd60f35df7acb4589091f154214af6d0d49d3"}, ] ipython = [ - {file = "ipython-8.2.0-py3-none-any.whl", hash = "sha256:1b672bfd7a48d87ab203d9af8727a3b0174a4566b4091e9447c22fb63ea32857"}, - {file = "ipython-8.2.0.tar.gz", hash = "sha256:70e5eb132cac594a34b5f799bd252589009905f05104728aea6a403ec2519dc1"}, + {file = "ipython-8.3.0-py3-none-any.whl", hash = "sha256:341456643a764c28f670409bbd5d2518f9b82c013441084ff2c2fc999698f83b"}, + {file = "ipython-8.3.0.tar.gz", hash = "sha256:807ae3cf43b84693c9272f70368440a9a7eaa2e7e6882dad943c32fbf7e51402"}, ] itsdangerous = [ {file = "itsdangerous-2.1.2-py3-none-any.whl", hash = "sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44"}, @@ -2313,16 +2313,16 @@ types-redis = [ {file = "types_redis-4.2.0-py3-none-any.whl", hash = "sha256:24c0effe59b2eef030733fd352fdcee6647a66611001aa25762475c3f26fb5f1"}, ] types-requests = [ - {file = "types-requests-2.27.24.tar.gz", hash = "sha256:e1cde99e92d5fb7afa0ee53924b211f4c47639516434d86dc84d53ec84fcfa8a"}, - {file = "types_requests-2.27.24-py3-none-any.whl", hash = "sha256:5501ec6bcc164c54a6598e7ee6581827ea0ac0472e9d33b9456d202892f8d94c"}, + {file = "types-requests-2.27.25.tar.gz", hash = "sha256:805ae7e38fd9d157153066dc4381cf585fd34dfa212f2fc1fece248c05aac571"}, + {file = "types_requests-2.27.25-py3-none-any.whl", hash = "sha256:2444905c89731dbcb6bbcd6d873a04252445df7623917c640e463b2b28d2a708"}, ] types-setuptools = [ {file = "types-setuptools-57.4.14.tar.gz", hash = "sha256:df02fe1dd244f58cf4e67cfc3d0a97930a2d61a72dd89f21d81c71017cd83f9a"}, {file = "types_setuptools-57.4.14-py3-none-any.whl", hash = "sha256:828f7e7e51e157876f47c80518b23ba0c3c36aa8081efd39d5d39f393938aec9"}, ] types-urllib3 = [ - {file = "types-urllib3-1.26.13.tar.gz", hash = "sha256:40f8fb5e8cd7d57e8aefdee3fdd5e930aa1a1bb4179cdadd55226cea588af790"}, - {file = "types_urllib3-1.26.13-py3-none-any.whl", hash = "sha256:ff7500641824f881b2c7bde4cc57e6c3abf03d1e005bae83aca752e77213a5da"}, + {file = "types-urllib3-1.26.14.tar.gz", hash = "sha256:2a2578e4b36341ccd240b00fccda9826988ff0589a44ba4a664bbd69ef348d27"}, + {file = "types_urllib3-1.26.14-py3-none-any.whl", hash = "sha256:5d2388aa76395b1e3999ff789ea5b3283677dad8e9bcf3d9117ba19271fd35d9"}, ] types-werkzeug = [ {file = "types-Werkzeug-1.0.9.tar.gz", hash = "sha256:5cc269604c400133d452a40cee6397655f878fc460e03fde291b9e3a5eaa518c"},