Skip to content

Commit

Permalink
fix: fix instantiate of Executor with write decorator (#5897)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed May 29, 2023
1 parent 18fb903 commit 042b580
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions jina/serve/executors/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ def _inject_owner_attrs(self, owner, name):
owner._write_methods.append(self.fn.__name__)

def __set_name__(self, owner, name):
_init_requests_by_class(owner)
if self._requests_decorator:
self._requests_decorator._inject_owner_attrs(owner, name, None, None)

self._inject_owner_attrs(owner, name)

setattr(owner, name, self.fn)
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/serve/executors/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ def foo(self, docs, **kwargs):

def test_write_decorator():
class WriteExecutor(Executor):
@write
@requests(on='/delete')
def delete(self, **kwargs):
pass

@requests(on='/bar')
@write
def bar(self, **kwargs):
pass

@requests(on='/index')
@write()
def index(self, **kwargs):
Expand All @@ -678,6 +688,8 @@ def index(self, **kwargs):
def update(self, **kwargs):
pass



@requests(on='/search')
def search(self, **kwargs):
pass
Expand All @@ -687,4 +699,4 @@ def foo(self, **kwargs):
pass

exec = WriteExecutor()
assert set(exec.write_endpoints) == {'/index', '/update'}
assert set(exec.write_endpoints) == {'/index', '/update', '/delete', '/bar'}

0 comments on commit 042b580

Please sign in to comment.