Skip to content

export_to_obj returns None, so the default temp output path is lost (unlike export_to_ply/export_to_gif/export_to_video) #15493

Backlog

Description

@MansurPro

Describe the bug

diffusers.utils.export_to_obj(mesh, output_obj_path=None) creates a temporary .obj file when no path is given, but never returns the path. The caller gets None and has no way to find the file it just wrote. Every other exporter in the same module (export_to_ply, export_to_gif, export_to_video) returns the path, and export_to_obj is otherwise a near copy of export_to_ply, so the missing return looks like an oversight. The function also has no docstring.

I would like to open a PR with the fix (a one-line return, a docstring, and a regression test). Could a maintainer acknowledge this first, per the "AI-assisted and agentic contributions" section of CONTRIBUTING.md? The fix was prepared with AI assistance (Claude Code) and reviewed by me.

Reproduction

import types, torch
from diffusers.utils import export_to_obj, export_to_ply

mesh = types.SimpleNamespace(  # minimal stand-in for the Shap-E mesh output
    verts=torch.tensor([[0.0, 0, 0], [1, 0, 0], [0, 1, 0]]),
    faces=torch.tensor([[0, 1, 2]]),
    vertex_channels={c: torch.rand(3) for c in "RGB"},
)
print("obj:", export_to_obj(mesh))
print("ply:", export_to_ply(mesh))

Actual output (current main, f982295):

obj: None
ply: /var/folders/.../tmpfd32c3di.ply

Expected: obj: /var/folders/.../tmpXXXX.obj.

Root cause

src/diffusers/utils/export_utils.py, export_to_obj (around lines 104-121): output_obj_path is set to a NamedTemporaryFile(...).name when None (line 106), the file is written (line 120-121), and the function ends without return output_obj_path. Compare export_to_ply, which ends with return output_ply_path.

Proposed fix

Add return output_obj_path, a -> str annotation and a short docstring. Add a regression test in tests/others/test_utils.py using a stub mesh (default path and explicit path).

(src/diffusers/utils/testing_utils.py and tests/testing_utils.py carry private copies of the same helper with the same omission. They are test helpers rather than public API, so I would leave them alone unless you prefer otherwise.)

System Info

  • Diffusers 0.44.0.dev0 (main at f982295), PyTorch 2.15.0, Python 3.12.13, macOS arm64, CPU.

Who can help?

@yiyixuxu @sayakpaul @DN6

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions