etebase-rs icon indicating copy to clipboard operation
etebase-rs copied to clipboard

test chunk_preupload_and_download fails with server v0.11.0

Open neduard opened this issue 1 year ago • 0 comments

Description

Hello! So I wanted to play a bit with the server and maybe put together an app.

I tried running the etebase-rs tests against a recent server instance. note I'm not deploying via docker: I'm simply running the current version of the server.

Hope this is an actual issue and not due to something silly on my side like a version mismatch :see_no_evil:

The test chunk_preupload_and_download seems to fail with Error: ServerError("Server error")

failures:

---- chunk_preupload_and_download stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /build/rustc-Oic09u/rustc-1.65.0+dfsg0ubuntu1/library/test/src/lib.rs:184:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Steps to reproduce:

  • run the server from the most recent commit. Note you'll need to comment out the ETEBASE_CREATE_USER_FUNC so that the tests can create new users.
diff --git a/etebase_server/settings.py b/etebase_server/settings.py
index 97ec7e9..63fcc21 100644
--- a/etebase_server/settings.py
+++ b/etebase_server/settings.py
@@ -140,7 +140,7 @@ config_locations = [
     "/etc/etebase-server/etebase-server.ini",
 ]
 
-ETEBASE_CREATE_USER_FUNC = "etebase_server.django.utils.create_user_blocked"
+#ETEBASE_CREATE_USER_FUNC = "etebase_server.django.utils.create_user_blocked"
 
 # Use config file if present
 if any(os.path.isfile(x) for x in config_locations):

  • run using vicorn etebase_server.asgi:application --host 0.0.0.0 --port 8000 --reload

Further debugging

I did a bit of digging:

The error happens here:

it_mgr.upload_content(&item)?;

This fails because it's trying to send binary data, but put_inner still calls prep_client and with_base_client which sets the Content-Type: application/msgpack header.

Now a workaround is fairly easy:

--- a/etebase_server/fastapi/msgpack.py
+++ b/etebase_server/fastapi/msgpack.py
@@ -18,6 +18,9 @@ class MsgpackRequest(Request):
             self._json = msgpack_decode(body)
         return self._json
 
+    async def raw(self) -> bytes:
+        return await super().body()
+
 
 class MsgpackResponse(Response):
     media_type = "application/msgpack"
diff --git a/etebase_server/fastapi/routers/collection.py b/etebase_server/fastapi/routers/collection.py
index c847743..8bd9211 100644
--- a/etebase_server/fastapi/routers/collection.py
+++ b/etebase_server/fastapi/routers/collection.py
@@ -610,7 +610,7 @@ async def chunk_update(
     collection: models.Collection = Depends(get_collection),
 ):
     # IGNORED FOR NOW: col_it = get_object_or_404(col.items, uid=collection_item_uid)
-    content_file = ContentFile(await request.body())
+    content_file = ContentFile(await request.raw())
     try:
         await chunk_save(chunk_uid, collection, content_file)
     except IntegrityError:

Though I don't think this is the right way of doing things? I'm happy to put together a PR though if someone can point me in the right direction.

Many Thanks!

neduard avatar Mar 24 '23 22:03 neduard