fix(generate): read WORKSPACE_DIR dynamically so relocated output isn't lost - #287
fix(generate): read WORKSPACE_DIR dynamically so relocated output isn't lost#287kevin9327 wants to merge 1 commit into
Conversation
Code reviewFound 1 issue:
modly/api/routers/generation.py Lines 72 to 74 in d4d5fc3 WORKSPACE_DIR usage inside sanitize_collection that this PR's import change would orphan)
modly/api/routers/generation.py Lines 96 to 98 in d4d5fc3 sanitize_collection is called unconditionally on every request)
Fix: rebase onto current - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
…'t lost `_run_generation` imported `WORKSPACE_DIR` by name, so it kept the value bound at import time. `POST /settings/paths` rebinds the registry's global when the user relocates the workspace, so every generation after that was written under the old directory and its `/workspace/...` URL 404'd in the app. Import the module instead and read `registry.WORKSPACE_DIR` at call time. `sanitize_collection()` (added to dev after this branch was cut) checks the collection's containment against the same root before the job is filed, so it reads the live binding the same way; a test now drives `generate_from_image` through it after a relocation, which is where a stale or missing module-level name surfaces as a NameError on every request.
cd8230a to
4f47b21
Compare
|
Rebased onto current Verification (venv with fastapi/python-multipart/httpx, run from |
What
After the workspace is relocated at runtime (
POST /settings/paths), 3D generations kept writing their output into the previous workspace directory, while/workspace/{path}served files from the new one — so the finished mesh 404s and never appears in the app.Why it triggers
api/routers/generation.pybound the workspace path withfrom services.generator_registry import WORKSPACE_DIR, capturing thePathat import time.POST /settings/paths→generator_registry.update_paths()rebinds theWORKSPACE_DIRmodule global (and repoints every loaded generator'soutputs_dir):Because
_run_generationused the stale imported name, it recomputedcoll_dir = WORKSPACE_DIR / collectionagainst the old directory and setgen.outputs_dirback to it — overriding the valueupdate_pathshad just written — then builtoutput_urlrelative to the same stale path./workspace/...reads the currentWORKSPACE_DIRdynamically, so it can't find the file.This affects both
/generate/from-imageand/workflow-runs/from-image(both funnel through_run_generation).Fix
Reference the module attribute
registry.WORKSPACE_DIRat call time instead of a name captured at import — the same wayoptimize.ply_to_splat(comment: "workspace dir may change at runtime") and the settings router already read it.Verification
api/tests/test_generation_router.py: drives_run_generationwith a fake generator after relocating the workspace, and asserts the output is filed under the current workspace (and thatoutput_urlmatches). Fails before, passes after.python -m unittest discover -s testsinapi/(venv withfastapi+python-multipart+httpx): all pass, 0 failures.