Skip to content

Commit 3f96d16

Browse files
committed
Fix backwards compat for DirectServerJsonResource
As that appears in the module API. Broke in #18595.
1 parent 434e389 commit 3f96d16

10 files changed

Lines changed: 30 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

synapse/http/additional_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(
5353
hs: homeserver
5454
handler: function to be called to handle the request.
5555
"""
56-
super().__init__(hs.get_clock())
56+
super().__init__(clock=hs.get_clock())
5757
self._handler = handler
5858

5959
async def _async_render(self, request: Request) -> Optional[Tuple[int, Any]]:

synapse/http/server.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@
4242
Protocol,
4343
Tuple,
4444
Union,
45+
cast,
4546
)
4647

4748
import attr
4849
import jinja2
4950
from canonicaljson import encode_canonical_json
5051
from zope.interface import implementer
5152

52-
from twisted.internet import defer, interfaces
53+
from twisted.internet import defer, interfaces, reactor
5354
from twisted.internet.defer import CancelledError
55+
from twisted.internet.interfaces import IReactorTime
5456
from twisted.python import failure
5557
from twisted.web import resource
5658

@@ -401,8 +403,15 @@ class DirectServeJsonResource(_AsyncResource):
401403
"""
402404

403405
def __init__(
404-
self, clock: Clock, canonical_json: bool = False, extract_context: bool = False
406+
self,
407+
canonical_json: bool = False,
408+
extract_context: bool = False,
409+
# Clock is optional as this class is exposed to the module API.
410+
clock: Optional[Clock] = None,
405411
):
412+
if clock is None:
413+
clock = Clock(cast(IReactorTime, reactor))
414+
406415
super().__init__(clock, extract_context)
407416
self.canonical_json = canonical_json
408417

@@ -460,7 +469,7 @@ def __init__(
460469
extract_context: bool = False,
461470
):
462471
self.clock = hs.get_clock()
463-
super().__init__(self.clock, canonical_json, extract_context)
472+
super().__init__(canonical_json, extract_context, clock=self.clock)
464473
# Map of path regex -> method -> callback.
465474
self._routes: Dict[Pattern[str], Dict[bytes, _PathEntry]] = {}
466475
self.hs = hs

synapse/rest/synapse/client/federation_whitelist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class FederationWhitelistResource(DirectServeJsonResource):
4444
PATH = "/_synapse/client/v1/config/federation_whitelist"
4545

4646
def __init__(self, hs: "HomeServer"):
47-
super().__init__(hs.get_clock())
47+
super().__init__(clock=hs.get_clock())
4848

4949
self._federation_whitelist = hs.config.federation.federation_domain_whitelist
5050

synapse/rest/synapse/client/jwks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
class JwksResource(DirectServeJsonResource):
3535
def __init__(self, hs: "HomeServer"):
36-
super().__init__(hs.get_clock(), extract_context=True)
36+
super().__init__(clock=hs.get_clock(), extract_context=True)
3737

3838
# Parameters that are allowed to be exposed in the public key.
3939
# This is done manually, because authlib's private to public key conversion

synapse/rest/synapse/client/oidc/backchannel_logout_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OIDCBackchannelLogoutResource(DirectServeJsonResource):
3535
isLeaf = 1
3636

3737
def __init__(self, hs: "HomeServer"):
38-
super().__init__(hs.get_clock())
38+
super().__init__(clock=hs.get_clock())
3939
self._oidc_handler = hs.get_oidc_handler()
4040

4141
async def _async_render_POST(self, request: SynapseRequest) -> None:

synapse/rest/synapse/client/pick_username.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def pick_username_resource(hs: "HomeServer") -> Resource:
6262

6363
class AvailabilityCheckResource(DirectServeJsonResource):
6464
def __init__(self, hs: "HomeServer"):
65-
super().__init__(hs.get_clock())
65+
super().__init__(clock=hs.get_clock())
6666
self._sso_handler = hs.get_sso_handler()
6767

6868
async def _async_render_GET(self, request: Request) -> Tuple[int, JsonDict]:

synapse/rest/synapse/client/rendezvous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MSC4108RendezvousSessionResource(DirectServeJsonResource):
3030
isLeaf = True
3131

3232
def __init__(self, hs: "HomeServer") -> None:
33-
super().__init__(hs.get_clock())
33+
super().__init__(clock=hs.get_clock())
3434
self._handler = hs.get_rendezvous_handler()
3535

3636
async def _async_render_GET(self, request: SynapseRequest) -> None:

synapse/rest/well_known.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ClientWellKnownResource(DirectServeJsonResource):
8686
isLeaf = 1
8787

8888
def __init__(self, hs: "HomeServer"):
89-
super().__init__(hs.get_clock())
89+
super().__init__(clock=hs.get_clock())
9090
self._well_known_builder = WellKnownBuilder(hs)
9191

9292
async def _async_render_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:

tests/test_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ async def callback(request: SynapseRequest) -> None:
401401

402402
class CancellableDirectServeJsonResource(DirectServeJsonResource):
403403
def __init__(self, clock: Clock):
404-
super().__init__(clock)
404+
super().__init__(clock=clock)
405405
self.clock = clock
406406

407407
@cancellable

0 commit comments

Comments
 (0)