From 7e29462a6ce1a9053b99c844813e8bf1fe808f3f Mon Sep 17 00:00:00 2001 From: Khakers <22665282+khakers@users.noreply.github.com> Date: Sun, 23 Jul 2023 11:54:51 -0700 Subject: [PATCH] fix migrations.py type hints for python 3.8 --- core/migrations.py | 13 +++++++++---- requirements.txt | Bin 2414 -> 1136 bytes 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/migrations.py b/core/migrations.py index 25dd757d43..c51521abab 100644 --- a/core/migrations.py +++ b/core/migrations.py @@ -1,6 +1,6 @@ import datetime import re -from typing import Optional +from typing import Optional, List from core import blocklist from core.models import getLogger @@ -76,7 +76,7 @@ def _convert_legacy_block_format( async def _convert_legacy_block_list( blocklist_dict: dict, - blocklist_batch: list[blocklist.BlocklistEntry], + blocklist_batch: List[blocklist.BlocklistEntry], block_type: blocklist.BlockType, bot, ) -> int: @@ -115,6 +115,10 @@ async def migrate_blocklist(bot): logger.info("preparing to migrate blocklist") skipped = 0 + if len(blocked_users) == 0 and len(bot.blocked_roles) == 0: + logger.info("no blocklist entries to migrate") + return + blocklist_batch: list[blocklist.BlocklistEntry] = [] logger.info(f"preparing to process {len(blocked_users)} blocked users") skipped += await _convert_legacy_block_list( @@ -133,8 +137,9 @@ async def migrate_blocklist(bot): ) logger.info("processed blocked roles") - await bot.api.db.blocklist.insert_many([x.__dict__ for x in blocklist_batch]) - blocklist_batch.clear() + if len(blocklist_batch) > 0: + await bot.api.db.blocklist.insert_many([x.__dict__ for x in blocklist_batch]) + blocklist_batch.clear() logger.info("clearing old blocklists") bot.blocked_users.clear() diff --git a/requirements.txt b/requirements.txt index 4abd41f3da65e262eb76e9e0fa4cb5470a2e2dad..bad033c0ce5adc8cbcf462bac0bc3c49f31ce315 100644 GIT binary patch literal 1136 zcmYjQ%Wm5+5WMqWOo)^p=|P90C~|3m009d0RL~S-&wfmmD4>MEAms%DG zZ9v4TiDHOFh=IM8L@n`w!{gG z(ik$t+bAEj-6N5)b&o4hE2HDB^@#NlR?LK;7^|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