Skip to content

draccus.dump can fail with 'TypeError: cannot create weak reference to str object' #61

@dlwh

Description

@dlwh

Summary

draccus.dump(...) can fail with:

TypeError: cannot create weak reference to 'str' object

We hit this while logging a dataclass config artifact from Levanter/Marin. The error is nonfatal in our caller, but it prevents config YAML artifact emission.

Context

Caller path:

with open(path, "w", encoding="utf-8") as f:
    draccus.dump(hparams, f, encoding="utf-8")

The surrounding caller is a tracker/logging utility that checks dataclasses.is_dataclass(hparams) before calling draccus.dump(...).

Observed traceback

TypeError: cannot create weak reference to 'str' object

The traceback originates from inside draccus.dump(...) when dumping our experiment config dataclass.

Notes

  • This showed up repeatedly in long-running training jobs.
  • In our case the training run continues, but config artifact logging is skipped.
  • I do not yet have a smaller standalone repro than “nested experiment config dataclass with string fields”, but I wanted to file the bug with the exact failure mode because it is recurring.

Expected behavior

draccus.dump(...) should successfully serialize the dataclass, or fail with a more direct validation error if the input type is unsupported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-generatedCreated by an automated coding agentbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions