Hi!
I recently updated my module to Dagger v0.21.0 and I'm running into an AST parsing issue when dynamically creating @dagger.object_type and @dagger.function.
Context
In my module, I dynamically attach functions to classes via decorators and set default values using a constant:
IsUpdateType = Annotated[bool, dagger.Doc("Update file or not")]
IS_UPDATE_DEFAULT: Final = False
# ...
@dagger.function
async def init(
self, is_update: IsUpdateType = IS_UPDATE_DEFAULT
) -> dagger.Directory:
# ...
sdk_language = final(
dagger.object_type(
add_enum_values_as_methods(SDKModuleOptions)(
type(sdk_name, (SDK,), {"init": final(init)})
)
)
)
# ...
The definition and the dynamic construction of the object live in the same file: https://github.com/fvonbergen/shiryu/blob/debug-python-ast-dagger-v0.21.0/src/shiryu/sdk/common/module.py#L78
The Error
When running the module, the AST fails to resolve the constant and falls back to a literal string:
WARNING [dagger.mod._analyzer.parser]: Unresolved name 'IS_UPDATE_DEFAULT' used in a constant expression at line 1363; falling back to the literal string.
Because it falls back to the string "IS_UPDATE_DEFAULT", the engine fails when trying to parse it as a boolean:
query module objects: failed to get schema: failed to load schema: failed to get schema for module "shiryu": failed to get field spec: failed to decode dagql default value for arg "isUpdate": strconv.ParseBool: parsing "IS_UPDATE_DEFAULT": invalid syntax
Reproduction Steps
Run the command using Dagger Engine v0.21.0:
$ mkdir test
$ cd test
$ dagger --mod=https://github.com/fvonbergen/shiryu.git@debug-python-ast-dagger-v0.21.0 call python init --project-name=test --project-directory=.
Question
- Is dynamic building of Dagger objects/functions not supported, or is this an edge-case bug in the AST analyzer?
Let me know if I can provide any more debugging info or context!
Thanks!