Ver código fonte

Allow handlers to return dataclasses instead of dicts

Stan Janssen 4 anos atrás
pai
commit
bc3885cb64
1 arquivos alterados com 4 adições e 0 exclusões
  1. 4 0
      openleadr/service/vtn_service.py

+ 4 - 0
openleadr/service/vtn_service.py

@@ -25,6 +25,8 @@ from .. import errors
 from ..messaging import create_message, parse_message
 from ..utils import generate_id
 
+from dataclasses import is_dataclass, asdict
+
 class VTNService:
 
     def __init__(self, vtn_id):
@@ -48,6 +50,8 @@ class VTNService:
                 result = await result
             if result is not None:
                 response_type, response_payload = result
+                if is_dataclass(response_payload):
+                    response_payload = asdict(response_payload)
             else:
                 response_type, response_payload = 'oadrResponse', {}