imbajin commented on code in PR #320:
URL: https://github.com/apache/hugegraph-ai/pull/320#discussion_r3115671569


##########
hugegraph-python-client/src/pyhugegraph/api/gremlin.py:
##########
@@ -26,14 +26,19 @@
 
 class GremlinManager(HugeParamsBase):

Review Comment:
   ‼️ **The double `@router.http` decorator does not work as intended — please 
simplify to one**
   
   The updated code adds two decorators to `exec()`:
   
   ```python
   @router.http("POST", "/gremlin")   # outer
   @router.http("POST", "gremlin")    # inner
   def exec(self, gremlin):
   ```
   
   This does **not** create a dual-route fallback. Here is what actually 
happens:
   
   **1. `RouterRegistry` is a singleton keyed by `func.__qualname__`** 
(`GremlinManager.exec`).
   Python applies decorators bottom-up (inner first), so `"gremlin"` is 
registered first, then `"/gremlin"` overwrites it. The registry ends up with 
only **one entry**: `/gremlin`.
   
   **2. The `wrapper` closure captures `path` by value at decoration time.**
   The outermost wrapper (for `"/gremlin"`) is what `exec` actually points to 
at runtime, so `make_request` is always built with `"/gremlin"`.
   
   **Net result**: the `"gremlin"` decorator is completely dead code — it 
registers a route that is immediately overwritten and its wrapper is never 
called. The behavior is identical to having only `@router.http("POST", 
"/gremlin")`.
   
   **Why `/gremlin` (with leading slash) is always correct for both 1.x and 
3.x:**
   
   Looking at `huge_requests.py:resolve()`:
   - A **relative** path like `gremlin` → gets the graph prefix prepended → 
resolves to `http://host:8080/graphs/{graph}/gremlin` ❌
   - An **absolute** path like `/gremlin` → `urljoin` replaces the path 
component → resolves to `http://host:8080/gremlin` ✅
   
   The Gremlin endpoint on HugeGraph server is always top-level `/gremlin`, 
regardless of version. The `gs_supported` branch inside `exec()` already 
handles the version difference (via `aliases`), so the path itself never needs 
to differ.
   
   **Fix — remove the redundant inner decorator:**
   
   ```suggestion
       @router.http("POST", "/gremlin")
       def exec(self, gremlin):
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to