Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 600ddc4

Browse files
committed
Update MatrixFederationRequest to calculate txn_id/uri.
1 parent 3203959 commit 600ddc4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

synapse/http/matrixfederationclient.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,23 @@ class MatrixFederationRequest:
153153
"""Query arguments.
154154
"""
155155

156-
txn_id: Optional[str] = None
157-
"""Unique ID for this request (for logging)
156+
txn_id: str = attr.ib(init=False)
157+
"""Unique ID for this request (for logging), autogenerated.
158158
"""
159159

160-
uri: bytes = attr.ib(init=False)
161-
"""The URI of this request
162-
"""
163-
164-
def __attrs_post_init__(self) -> None:
160+
@txn_id.default
161+
def _create_txn_id(self) -> str:
165162
global _next_id
166163
txn_id = "%s-O-%s" % (self.method, _next_id)
167164
_next_id = (_next_id + 1) % (MAXINT - 1)
165+
return txn_id
168166

169-
object.__setattr__(self, "txn_id", txn_id)
167+
uri: bytes = attr.ib(init=False)
168+
"""The URI of this request, generated from the above information.
169+
"""
170170

171+
@uri.default
172+
def _default_uri(self) -> bytes:
171173
destination_bytes = self.destination.encode("ascii")
172174
path_bytes = self.path.encode("ascii")
173175
query_bytes = encode_query_args(self.query)
@@ -183,7 +185,7 @@ def __attrs_post_init__(self) -> None:
183185
b"",
184186
)
185187
)
186-
object.__setattr__(self, "uri", uri)
188+
return uri
187189

188190
def get_json(self) -> Optional[JsonDict]:
189191
if self.json_callback:

0 commit comments

Comments
 (0)