dagger/dagger · error · ObjectNotFoundError
Main object with name '{self._main_name}' not found or class
Error message
Main object with name '{self._main_name}' not found or class not decorated with '@dagger.object_type'
If you believe the module name '{MODULE_NAME}' is incorrectly being converted into PascalCase, please file a bug report. What it means
The module's main object (module name converted to PascalCase) must correspond to a class decorated with @dagger.object_type in the registered objects map. If get_object(main_name) raises ObjectNotFoundError, _typedefs re-raises with guidance: either the class is missing the decorator or the PascalCase conversion of MODULE_NAME doesn't match the class name.
Source
Thrown at sdk/python/src/dagger/mod/_module.py:139
output = json.dumps(result)
except TypeError as e:
raise RegistrationError(str(e), e) from e
await anyio.Path(TYPE_DEF_FILE).write_text(output)
async def _typedefs(self) -> str: # noqa: C901, PLR0912, PLR0915
if not self._main_name:
msg = "Main object name can't be empty"
raise ValueError(msg)
try:
self.get_object(self._main_name)
except ObjectNotFoundError as e:
msg = (
f"Main object with name '{self._main_name}' not found or class not "
"decorated with '@dagger.object_type'\n"
f"If you believe the module name '{MODULE_NAME}' is incorrectly "
"being converted into PascalCase, please file a bug report."
)
raise ObjectNotFoundError(msg, extra=e.extra) from None
mod = dag.module()
# Object types
for obj_name, obj_type in self._objects.items():
if self.is_main(obj_type):
# Only the main object's constructor is needed.
# It's the entrypoint to the module.
obj_type.get_constructor(self._converter)
# Module description from main object's parent module
if desc := get_parent_module_doc(obj_type.cls):
mod = mod.with_description(desc)
# Object/interface type
type_def = dag.type_def()
if obj_type.interface:
type_def = type_def.with_interface(View on GitHub (pinned to 82ba2681db)
Solutions
- Ensure a class named exactly PascalCase(your-module-name) exists and is decorated with @dagger.object_type (e.g. module 'my-mod' -> class MyMod).
- If the desired class name differs, rename the module directory or the class so they correspond.
- Verify the module's __init__.py imports the main class so it's registered.
- If PascalCase conversion is wrong (e.g. digits/acronyms), file a bug report with the SDK as the message suggests.
Example fix
// before
# src/my_mod/__init__.py
class MyModule: # no decorator, wrong name for 'my-mod'
pass
// after
import dagger
@dagger.object_type
class MyMod:
... Defensive patterns
Strategy: validation
Validate before calling
import re
module_name = "my-mod" # from dagger.json
expected = "".join(p.capitalize() for p in re.split(r"[-_]", module_name))
# ensure a class with this exact name exists and is decorated:
# @dagger.object_type
# class MyMod: ...
assert any(name == expected for name in globals()), f"missing main object class {expected}" Type guard
def has_main_object(module_name: str, objects: dict) -> bool:
pascal = "".join(p.capitalize() for p in re.split(r"[-_]", module_name))
return pascal in objects Try / catch
try:
await module.register()
except ObjectNotFoundError as e:
logger.error("main object missing: %s", e)
raise SystemExit(1) from e Prevention
- Keep the main class name equal to PascalCase of the module directory name.
- Always decorate the main class with @dagger.object_type.
- Import the main class in the module entrypoint (__init__.py).
- After renaming a module, rename the class too.
When it happens
Trigger: Running a Python Dagger module where no class named PascalCase(module_name) exists, or it exists but lacks @dagger.object_type; renaming the module directory without renaming the main class; main class defined in a file not imported by the entrypoint.
Common situations: Renaming a module (e.g. dir 'my-mod' requires class 'MyMod'); a typo'd class name; moving the main object into another module without updating names; forgetting the decorator after refactoring.
Related errors
- {str(e)}
- Seems like the SDK module isn't registering the types correc
- struct types must be named
- unsupported {context}: {typ.hint!r}
- Failed to serialize final result as JSON: {e}
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/c1390515d4d8c3c2.
Report an issue: GitHub.