Ewwww monkeypatch library bug I'm so sorry code gods. Bug reported at https://github.com/meshcore-dev/meshcore_py/issues/65

This commit is contained in:
Jack Kingsman
2026-03-07 21:10:07 -08:00
parent 2257c091e8
commit 69c812cfd4
+20
View File
@@ -6,11 +6,31 @@ from contextlib import asynccontextmanager, nullcontext
from pathlib import Path from pathlib import Path
from meshcore import MeshCore from meshcore import MeshCore
from meshcore.commands.contact import ContactCommands
from app.config import settings from app.config import settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# ---------------------------------------------------------------------------
# Monkey-patch for meshcore library bug (meshcore==2.2.28):
# ContactCommands.update_contact reads out_path_hash_mode from the contact
# dict into a local variable, but line 145 uses the function *parameter*
# path_hash_mode (which defaults to None) instead of the local variable.
# This causes TypeError when add_contact → update_contact is called without
# an explicit path_hash_mode. Fix by defaulting to the dict value.
# ---------------------------------------------------------------------------
_original_update_contact = ContactCommands.update_contact
async def _patched_update_contact(self, contact, path=None, flags=None, path_hash_mode=None):
if path_hash_mode is None and path is None:
path_hash_mode = contact.get("out_path_hash_mode", 0)
return await _original_update_contact(self, contact, path, flags, path_hash_mode)
ContactCommands.update_contact = _patched_update_contact
class RadioOperationError(RuntimeError): class RadioOperationError(RuntimeError):
"""Base class for shared radio operation lock errors.""" """Base class for shared radio operation lock errors."""