From e85bc4436c4e146ab3ab7958f7cd2427209714c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 12 Jun 2023 19:59:22 +0200 Subject: [PATCH] Continued: - ops, don't double-fetch a single row, causing 2nd invocation of fetchone() to return None as the first one already fetched it --- fba/instances.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fba/instances.py b/fba/instances.py index e8db229..a6109df 100644 --- a/fba/instances.py +++ b/fba/instances.py @@ -340,7 +340,7 @@ def is_recent(domain: str) -> bool: return recently def deobscure(char: str, domain: str, blocked_hash: str = None) -> tuple: - #print(f"DEBUG: char='{char}',domain='{domain}',blocked_hash='{blocked_hash}' - CALLED!") + # DEBUG: print(f"DEBUG: char='{char}',domain='{domain}',blocked_hash='{blocked_hash}' - CALLED!") if not isinstance(char, str): raise ValueError(f"Parameter char[]='{type(char)}' is not 'str'") elif char == "": @@ -353,19 +353,25 @@ def deobscure(char: str, domain: str, blocked_hash: str = None) -> tuple: raise ValueError(f"Parameter blocked_hash[]='{type(blocked_hash)}' is not 'str'") if isinstance(blocked_hash, str): + # DEBUG: print(f"DEBUG: Looking up blocked_hash='{blocked_hash}' ...") fba.cursor.execute( "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? LIMIT 1", [blocked_hash] ) - if fba.cursor.fetchone() is None: - #print(f"DEBUG: blocked_hash='{blocked_hash}' not found, trying domain='{domain}' ...") + row = fba.cursor.fetchone() + # DEBUG: print(f"DEBUG: row[]='{type(row)}'") + + if row is None: + # DEBUG: print(f"DEBUG: blocked_hash='{blocked_hash}' not found, trying domain='{domain}' ...") return deobscure(char, domain) else: + # DEBUG: print(f"DEBUG: Looking up domain='{domain}' ...") fba.cursor.execute( "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [domain.replace(char, "_")] ) - row = fba.cursor.fetchone() + row = fba.cursor.fetchone() + # DEBUG: print(f"DEBUG: row[]='{type(row)}'") - #print(f"DEBUG: row[]='{type(row)}' - EXIT!") + # DEBUG: print(f"DEBUG: row[]='{type(row)}' - EXIT!") return row -- 2.39.5