Skip to content

Commit

Permalink
Merge pull request #672 from BoostryJP/feature/#671
Browse files Browse the repository at this point in the history
Remove "Failed to decrypt" error log from processor_modify_personal_info.py
  • Loading branch information
YoshihitoAso authored Jul 31, 2024
2 parents f214bd6 + 54450cc commit 18e0021
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
22 changes: 22 additions & 0 deletions batch/processor_modify_personal_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

import asyncio
import logging
import sys
from asyncio import Event
from typing import Sequence, Set
Expand Down Expand Up @@ -58,6 +59,20 @@
LOG = batch_log.get_logger(process_name=process_name)


class SupressDecryptFailedLogFilter(logging.Filter):
def filter(self, record: logging.LogRecord):
if (
record.levelname == "ERROR"
and isinstance(record.msg, str)
and "Failed to decrypt" in record.msg
):
return False
return True


LOG.addFilter(SupressDecryptFailedLogFilter())


class Processor:
def __init__(self, is_shutdown: Event):
self.is_shutdown = is_shutdown
Expand Down Expand Up @@ -97,6 +112,7 @@ async def process(self):
return

# Get target PersonalInfo contract accessor
target_contract_accessor = None
for contract_accessor in contract_accessor_list:
is_registered = await AsyncContractUtils.call_function(
contract=contract_accessor.personal_info_contract,
Expand All @@ -111,6 +127,9 @@ async def process(self):
target_contract_accessor = contract_accessor
break

if target_contract_accessor is None:
continue

is_modify = await self.__modify_personal_info(
temporary=temporary,
idx_personal_info=idx_personal_info,
Expand All @@ -124,6 +143,9 @@ async def process(self):
# Once all investors' personal information has been updated,
# update the status of the issuer's RSA key.
if count == completed_count:
LOG.info(
f"Modify personal info process is completed: issuer={temporary.issuer_address}"
)
await self.__sink_on_account(
db_session=db_session, issuer_address=temporary.issuer_address
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/explorer/src/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from typing import Any

from aiohttp import ClientSession
from cache import AsyncTTL

from app.model.schema import (
BlockDataDetail,
Expand All @@ -32,6 +31,7 @@
TxDataDetail,
TxDataListResponse,
)
from cache import AsyncTTL


class ApiNotEnabledException(Exception):
Expand Down
15 changes: 14 additions & 1 deletion tests/batch/test_processor_modify_personal_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@

@pytest.fixture(scope="function")
def processor(db):
LOG = logging.getLogger("background")
default_log_level = LOG.level
LOG.setLevel(logging.DEBUG)
LOG.propagate = True
return Processor(asyncio.Event())
LOG.propagate = False
LOG.setLevel(default_log_level)


def deploy_personal_info_contract(issuer_user):
Expand Down Expand Up @@ -183,7 +189,7 @@ class TestProcessor:
# Execute Batch Run 2nd: changed RSA
# Execute Batch Run 3rd: modified PersonalInfo
@pytest.mark.asyncio
async def test_normal_1(self, processor, db):
async def test_normal_1(self, processor, db, caplog: pytest.LogCaptureFixture):
user_1 = config_eth_account("user1")
issuer_address_1 = user_1["address"]

Expand Down Expand Up @@ -481,6 +487,13 @@ async def test_normal_1(self, processor, db):
await processor.process()

# assertion(Run 3rd)
assert "Failed to decrypt" not in caplog.text
assert (
"background",
logging.INFO,
f"Modify personal info process is completed: issuer={user_1['address']}",
) in caplog.record_tuples

db.rollback()
_account = db.scalars(select(Account).limit(1)).first()
assert _account.issuer_address == user_1["address"]
Expand Down

0 comments on commit 18e0021

Please sign in to comment.