Skip to content

Commit

Permalink
Add check to prevent null violation
Browse files Browse the repository at this point in the history
  • Loading branch information
mzfr authored and mzfr committed Aug 21, 2020
1 parent cb4fe89 commit 26d3a43
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tanner/migration_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
from tanner import redis_client, postgres_client, dbutils


async def check_session_data(result):
if result["location"] == "NA":
result["location"] = dict(
country=None, country_code=None, city=None, zip_code=0,
)

if "user_agent" not in result:
result["user_agent"] = ""


async def main():
r_client = await redis_client.RedisClient.get_redis_client()
pg_client = await postgres_client.PostgresClient().get_pg_client()
Expand All @@ -22,11 +32,7 @@ async def main():
try:
session = await r_client.zrange(key, encoding="utf-8")
result = json.loads(session[0])

if result["location"] == "NA":
result["location"] = dict(
country=None, country_code=None, city=None, zip_code=0,
)
await check_session_data(result)

try:
await dbutils.DBUtils.add_analyzed_data(result, pg_client)
Expand All @@ -46,8 +52,8 @@ async def main():
except aioredis.errors.ReplyError:
continue

self.redis_client.close()
await self.redis_client.wait_closed()
r_client.close()
await r_client.wait_closed()
pg_client.close()
await pg_client.wait_closed()

Expand Down

0 comments on commit 26d3a43

Please sign in to comment.