#Enum issue inside nested connection
1 messages · Page 1 of 1 (latest)
It's the same version, and dev build: v0.18.15-010101000000-dev-5efecbf8f2e5
Hmmm... this seems to happen only on the new self calls PR, specifically in the new moduleTypeDefs function so it's in a phase where the module isn't fully loaded yet. Maybe that view isn't being applied yet at this point? Can we move that needle? Or maybe it's just missing the thing that applies the view?
It's getting called at this point in core/schema/modulesource.go: https://github.com/dagger/dagger/pull/10584/files#diff-35a72c75f37c6dcddd3e1df88cccf5a8b22ac1f6304301c66c3a1c7394ff0eafR2274
I made a repro and it's ok in v0.18.14. Will test against main now, but I suspect it only happens in the self calls PR since it changes how modules are loaded.
Btw, when you changed the codegen to refer to other members like:
class TypeDefKind(Enum):
STRING = "STRING_KIND"
STRING_KIND = STRING
Was the motivation simply to make an alias or is there a reason not to:
class TypeDefKind(Enum):
STRING = "STRING"
STRING_KIND = "STRING_KIND"
no real reason, it can just be changed back if you like
but go/typescript did it - i found it much clearer as to which ones were aliases
oh wait wait. yes there is a reason.
the values should be the same
otherwise, we lose the property that STRING == STRING_KIND
Thing is in the first case the type of STRING is a string, while the type of STRING_KIND is an enum member.
The proper way to make an alias in a Python enum is just to have the same value.
😢 right okay, sorry, that's a my bad then
the codegen result should be:
class TypeDefKind(Enum):
STRING = "STRING_KIND"
STRING_KIND = "STRING_KIND"
A simple example:
import enum
class Test(enum.Enum):
ONE = "ONE"
UNO = "ONE"
print("By name:", Test["UNO"].name)
# Output: By name: ONE
lemme revert that change
it used to be like this, i did it in https://github.com/dagger/dagger/pull/10632/commits/caac8b23db2452d67d83dec0ae9af72a67c45528
Just reverting will produce:
class TypeDefKind(Enum):
STRING = "STRING"
STRING_KIND = "STRING_KIND"
Instead of this though:
class TypeDefKind(Enum):
STRING = "STRING_KIND"
STRING_KIND = "STRING_KIND"
No issue on main too. Going to test that PR the same way or see if it only happens within moduleTypeDefs
@hexed saddle, is there a way to confirm enum values with a GraphQL query (with dagger listen)?
I've created this repro:
package main
import (
"context"
"dagger/nested/internal/dagger"
)
type Nested struct{}
func (m *Nested) Test(ctx context.Context) (string, error) {
var code string = `
import pprint
import anyio
import graphql
from gql.dsl import DSLSchema
import dagger
from dagger import dag
def get_value(value, schema) -> str:
if value.ast_node and (directive := schema.get_directive("enumValue")):
args = graphql.get_directive_values(directive, value.ast_node)
if args:
return args["value"]
return value.value
async def main():
async with await dagger.connect():
print("Version:", await dag.version())
schema = DSLSchema(await dag._ctx.conn.session.get_schema())
pprint.pprint(
{
name: get_value(value, schema)
for name, value in schema.TypeDef.withKind._get_argument(
"kind"
).type.of_type.values.items()
}
)
anyio.run(main)
`
return dag.Container().
From("ghcr.io/astral-sh/uv:debian-slim").
WithNewFile("/script.py", code).
WithExec([]string{"uv", "run", "--with", "dagger-io", "/script.py"}, dagger.ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
}).
Stdout(ctx)
}
But it's returning this:
{'BOOLEAN': 'BOOLEAN',
'BOOLEAN_KIND': 'BOOLEAN_KIND',
'ENUM': 'ENUM',
'ENUM_KIND': 'ENUM_KIND',
'FLOAT': 'FLOAT',
'FLOAT_KIND': 'FLOAT_KIND',
'INPUT': 'INPUT',
'INPUT_KIND': 'INPUT_KIND',
'INTEGER': 'INTEGER',
'INTEGER_KIND': 'INTEGER_KIND',
'INTERFACE': 'INTERFACE',
'INTERFACE_KIND': 'INTERFACE_KIND',
'LIST': 'LIST',
'LIST_KIND': 'LIST_KIND',
'OBJECT': 'OBJECT',
'OBJECT_KIND': 'OBJECT_KIND',
'SCALAR': 'SCALAR',
'SCALAR_KIND': 'SCALAR_KIND',
'STRING': 'STRING',
'STRING_KIND': 'STRING_KIND',
'VOID': 'VOID',
'VOID_KIND': 'VOID_KIND'}
I expected 'STRING': 'STRING_KIND' for example.
it potentially looks like you're always following the return value.value path
Oh wait, I may need the insert_stubs thing?
and not looking at the enumValue
ah yes
you definitely need that
The order may still be wrong, right?
class TypeDefKind(Enum):
STRING = "STRING_KIND"
STRING_KIND = "STRING_KIND"
It's declared like so:
TypeDefKindString = TypeDefKinds.Register("STRING_KIND", "A string value.")
_ = TypeDefKinds.AliasView("STRING", "STRING_KIND", enumView)
Which means that it should have this order:
class TypeDefKind(Enum):
STRING_KIND = "STRING_KIND"
STRING = "STRING_KIND"
Otherwise dagger.TypeDefKind.STRING_KIND becomes an alias of dagger.TypeDefKind.STRING instead, meaning the member's name will be "STRING" instead of "STRING_KIND".
mmmm, indeed. the name should be the original STRING_KIND
this is definitely true in go already
So you can't sort those values. How can you tell in codegen which one is the alias or not? In this case I can check if name == value, but what about user defined ones?
in go + typescript, we do: https://github.com/dagger/dagger/blob/aaa13befbe949553e6f0f3deb1b03ff5be2f34ec/cmd/codegen/generator/go/templates/functions.go#L184-L208
An open-source runtime for composable workflows. Great for AI agents and CI/CD. - dagger/dagger
they're not sorted, they're bucketed by value first
then the first value in the bucket is the "original"
i think the only fix for python needed is to avoid the sorting step?
Yep, I think so.
@hexed saddle, indeed this fixes my problem. I've sorted by value after grouping which effectively keeps the same overall sort but flips the original value vs alias. I can push the change to your branch.