Closed yxtay closed 1 week ago
Should guard agains missing close
method. Can you send a PR for this?
Will you be able to point me to the code where this should be done?
Along at this very line:
File "venv/lib/python3.10/site-packages/_bentoml_sdk/service/dependency.py", line 106, in close await t.cast("RemoteProxy[t.Any]", self._resolved).close()
Check the .close()
exists before calling it, you can add a condition check to the if
statement just above it
Describe the bug
Hi,
I am encountering
AttributeError
when usingTestClient
due toclose
being called on service dependencies. Below is the reproducible example.In the documentation, a simple service is demoed. But this doesn't work with model composition. https://docs.bentoml.com/en/latest/guides/testing.html#http-behavior-tests
I believe this is linked to using
TestClient
as a context manager calls the lifespan handler. https://www.starlette.io/lifespan/#running-lifespan-in-testsThe service file
Using
TestClient
directly on theModel
is fine.But using
TestClient
onService
throwsAttributeError
. Stack trace is below.A possible workaround is to add an empty async
close
method to the dependent model as I added as a comment. I think this should be better handled in thebentoml.depends
decorator instead.To reproduce
Example as provided above.
Expected behavior
AttributeError
should not be thrown when usingTestClient
on service with model composition.Environment
bentoml==1.3.11
python==3.10.13
platform: ubuntu 22.04