status
stringclasses 1
value | repo_name
stringclasses 31
values | repo_url
stringclasses 31
values | issue_id
int64 1
104k
| title
stringlengths 4
233
| body
stringlengths 0
186k
โ | issue_url
stringlengths 38
56
| pull_url
stringlengths 37
54
| before_fix_sha
stringlengths 40
40
| after_fix_sha
stringlengths 40
40
| report_datetime
timestamp[us, tz=UTC] | language
stringclasses 5
values | commit_datetime
timestamp[us, tz=UTC] | updated_file
stringlengths 7
188
| chunk_content
stringlengths 1
1.03M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | }
}
func (r *Client) LoadFunctionArgFromID(id FunctionArgID) *FunctionArg {
q := r.q.Select("loadFunctionArgFromID")
q = q.Arg("id", id)
return &FunctionArg{
q: q,
c: r.c,
}
}
func (r *Client) LoadFunctionFromID(id FunctionID) *Function {
q := r.q.Select("loadFunctionFromID")
q = q.Arg("id", id)
return &Function{
q: q,
c: r.c,
}
}
func (r *Client) LoadGeneratedCodeFromID(id GeneratedCodeID) *GeneratedCode {
q := r.q.Select("loadGeneratedCodeFromID")
q = q.Arg("id", id)
return &GeneratedCode{
q: q,
c: r.c,
}
}
func (r *Client) LoadGitRefFromID(id GitRefID) *GitRef {
q := r.q.Select("loadGitRefFromID")
q = q.Arg("id", id)
return &GitRef{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | q: q,
c: r.c,
}
}
func (r *Client) LoadGitRepositoryFromID(id GitRepositoryID) *GitRepository {
q := r.q.Select("loadGitRepositoryFromID")
q = q.Arg("id", id)
return &GitRepository{
q: q,
c: r.c,
}
}
func (r *Client) LoadModuleFromID(id ModuleID) *Module {
q := r.q.Select("loadModuleFromID")
q = q.Arg("id", id)
return &Module{
q: q,
c: r.c,
}
}
func (r *Client) LoadSecretFromID(id SecretID) *Secret {
q := r.q.Select("loadSecretFromID")
q = q.Arg("id", id)
return &Secret{
q: q,
c: r.c,
}
}
func (r *Client) LoadServiceFromID(id ServiceID) *Service {
q := r.q.Select("loadServiceFromID") |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | q = q.Arg("id", id)
return &Service{
q: q,
c: r.c,
}
}
func (r *Client) LoadSocketFromID(id SocketID) *Socket {
q := r.q.Select("loadSocketFromID")
q = q.Arg("id", id)
return &Socket{
q: q,
c: r.c,
}
}
func (r *Client) LoadTypeDefFromID(id TypeDefID) *TypeDef {
q := r.q.Select("loadTypeDefFromID")
q = q.Arg("id", id)
return &TypeDef{
q: q,
c: r.c,
}
}
func (r *Client) Module() *Module {
q := r.q.Select("module")
return &Module{
q: q,
c: r.c,
}
}
type ModuleConfigOpts struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | Subpath string
}
func (r *Client) ModuleConfig(sourceDirectory *Directory, opts ...ModuleConfigOpts) *ModuleConfig {
assertNotNil("sourceDirectory", sourceDirectory)
q := r.q.Select("moduleConfig")
for i := len(opts) - 1; i >= 0; i-- {
if !querybuilder.IsZeroValue(opts[i].Subpath) {
q = q.Arg("subpath", opts[i].Subpath)
}
}
q = q.Arg("sourceDirectory", sourceDirectory)
return &ModuleConfig{
q: q,
c: r.c,
}
}
type PipelineOpts struct {
Description string
Labels []PipelineLabel
}
func (r *Client) Pipeline(name string, opts ...PipelineOpts) *Client {
q := r.q.Select("pipeline")
for i := len(opts) - 1; i >= 0; i-- {
if !querybuilder.IsZeroValue(opts[i].Description) {
q = q.Arg("description", opts[i].Description) |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | }
if !querybuilder.IsZeroValue(opts[i].Labels) {
q = q.Arg("labels", opts[i].Labels)
}
}
q = q.Arg("name", name)
return &Client{
q: q,
c: r.c,
}
}
func (r *Client) Secret(id SecretID) *Secret {
q := r.q.Select("secret")
q = q.Arg("id", id)
return &Secret{
q: q,
c: r.c,
}
}
func (r *Client) SetSecret(name string, plaintext string) *Secret {
q := r.q.Select("setSecret")
q = q.Arg("name", name)
q = q.Arg("plaintext", plaintext)
return &Secret{
q: q,
c: r.c,
}
}
type SocketOpts struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | ID SocketID
}
func (r *Client) Socket(opts ...SocketOpts) *Socket {
q := r.q.Select("socket")
for i := len(opts) - 1; i >= 0; i-- {
if !querybuilder.IsZeroValue(opts[i].ID) {
q = q.Arg("id", opts[i].ID)
}
}
return &Socket{
q: q,
c: r.c,
}
}
func (r *Client) TypeDef() *TypeDef {
q := r.q.Select("typeDef")
return &TypeDef{
q: q,
c: r.c,
}
}
type Secret struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | q *querybuilder.Selection
c graphql.Client
id *SecretID
plaintext *string
}
func (r *Secret) ID(ctx context.Context) (SecretID, error) {
if r.id != nil {
return *r.id, nil
}
q := r.q.Select("id")
var response SecretID
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
func (r *Secret) XXX_GraphQLType() string {
return "Secret"
}
func (r *Secret) XXX_GraphQLIDType() string {
return "SecretID"
}
func (r *Secret) XXX_GraphQLID(ctx context.Context) (string, error) {
id, err := r.ID(ctx)
if err != nil {
return "", err
}
return string(id), nil
}
func (r *Secret) MarshalJSON() ([]byte, error) {
id, err := r.ID(context.Background()) |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | if err != nil {
return nil, err
}
return json.Marshal(id)
}
func (r *Secret) Plaintext(ctx context.Context) (string, error) {
if r.plaintext != nil {
return *r.plaintext, nil
}
q := r.q.Select("plaintext")
var response string
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
type Service struct {
q *querybuilder.Selection
c graphql.Client
endpoint *string
hostname *string
id *ServiceID
start *ServiceID
stop *ServiceID
}
type ServiceEndpointOpts struct {
Port int
Scheme string
}
func (r *Service) Endpoint(ctx context.Context, opts ...ServiceEndpointOpts) (string, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | if r.endpoint != nil {
return *r.endpoint, nil
}
q := r.q.Select("endpoint")
for i := len(opts) - 1; i >= 0; i-- {
if !querybuilder.IsZeroValue(opts[i].Port) {
q = q.Arg("port", opts[i].Port)
}
if !querybuilder.IsZeroValue(opts[i].Scheme) {
q = q.Arg("scheme", opts[i].Scheme)
}
}
var response string
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
func (r *Service) Hostname(ctx context.Context) (string, error) {
if r.hostname != nil {
return *r.hostname, nil
}
q := r.q.Select("hostname")
var response string
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
func (r *Service) ID(ctx context.Context) (ServiceID, error) {
if r.id != nil {
return *r.id, nil |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | }
q := r.q.Select("id")
var response ServiceID
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
func (r *Service) XXX_GraphQLType() string {
return "Service"
}
func (r *Service) XXX_GraphQLIDType() string {
return "ServiceID"
}
func (r *Service) XXX_GraphQLID(ctx context.Context) (string, error) {
id, err := r.ID(ctx)
if err != nil {
return "", err
}
return string(id), nil
}
func (r *Service) MarshalJSON() ([]byte, error) {
id, err := r.ID(context.Background())
if err != nil {
return nil, err
}
return json.Marshal(id)
}
func (r *Service) Ports(ctx context.Context) ([]Port, error) {
q := r.q.Select("ports")
q = q.Select("description port protocol")
type ports struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | Description string
Port int
Protocol NetworkProtocol
}
convert := func(fields []ports) []Port {
out := []Port{}
for i := range fields {
val := Port{description: &fields[i].Description, port: &fields[i].Port, protocol: &fields[i].Protocol}
out = append(out, val)
}
return out
}
var response []ports
q = q.Bind(&response)
err := q.Execute(ctx, r.c)
if err != nil {
return nil, err
}
return convert(response), nil
}
func (r *Service) Start(ctx context.Context) (*Service, error) {
q := r.q.Select("start")
return r, q.Execute(ctx, r.c)
}
func (r *Service) Stop(ctx context.Context) (*Service, error) {
q := r.q.Select("stop")
return r, q.Execute(ctx, r.c)
}
type Socket struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | q *querybuilder.Selection
c graphql.Client
id *SocketID
}
func (r *Socket) ID(ctx context.Context) (SocketID, error) {
if r.id != nil {
return *r.id, nil
}
q := r.q.Select("id")
var response SocketID
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
func (r *Socket) XXX_GraphQLType() string {
return "Socket"
}
func (r *Socket) XXX_GraphQLIDType() string {
return "SocketID"
}
func (r *Socket) XXX_GraphQLID(ctx context.Context) (string, error) {
id, err := r.ID(ctx)
if err != nil {
return "", err
}
return string(id), nil |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | }
func (r *Socket) MarshalJSON() ([]byte, error) {
id, err := r.ID(context.Background())
if err != nil {
return nil, err
}
return json.Marshal(id)
}
type TypeDef struct {
q *querybuilder.Selection
c graphql.Client
id *TypeDefID
kind *TypeDefKind
optional *bool
}
type WithTypeDefFunc func(r *TypeDef) *TypeDef
func (r *TypeDef) With(f WithTypeDefFunc) *TypeDef {
return f(r)
}
func (r *TypeDef) AsList() *ListTypeDef {
q := r.q.Select("asList")
return &ListTypeDef{
q: q,
c: r.c,
}
}
func (r *TypeDef) AsObject() *ObjectTypeDef {
q := r.q.Select("asObject")
return &ObjectTypeDef{
q: q, |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | c: r.c,
}
}
func (r *TypeDef) ID(ctx context.Context) (TypeDefID, error) {
if r.id != nil {
return *r.id, nil
}
q := r.q.Select("id")
var response TypeDefID
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
func (r *TypeDef) XXX_GraphQLType() string {
return "TypeDef"
}
func (r *TypeDef) XXX_GraphQLIDType() string {
return "TypeDefID"
}
func (r *TypeDef) XXX_GraphQLID(ctx context.Context) (string, error) {
id, err := r.ID(ctx)
if err != nil {
return "", err
}
return string(id), nil
}
func (r *TypeDef) MarshalJSON() ([]byte, error) {
id, err := r.ID(context.Background())
if err != nil {
return nil, err
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | return json.Marshal(id)
}
func (r *TypeDef) Kind(ctx context.Context) (TypeDefKind, error) {
if r.kind != nil {
return *r.kind, nil
}
q := r.q.Select("kind")
var response TypeDefKind
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
func (r *TypeDef) Optional(ctx context.Context) (bool, error) {
if r.optional != nil {
return *r.optional, nil
}
q := r.q.Select("optional")
var response bool
q = q.Bind(&response)
return response, q.Execute(ctx, r.c)
}
func (r *TypeDef) WithConstructor(function *Function) *TypeDef {
assertNotNil("function", function)
q := r.q.Select("withConstructor")
q = q.Arg("function", function)
return &TypeDef{
q: q,
c: r.c,
}
}
type TypeDefWithFieldOpts struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | Description string
}
func (r *TypeDef) WithField(name string, typeDef *TypeDef, opts ...TypeDefWithFieldOpts) *TypeDef {
assertNotNil("typeDef", typeDef)
q := r.q.Select("withField")
for i := len(opts) - 1; i >= 0; i-- {
if !querybuilder.IsZeroValue(opts[i].Description) {
q = q.Arg("description", opts[i].Description)
}
}
q = q.Arg("name", name)
q = q.Arg("typeDef", typeDef)
return &TypeDef{
q: q, |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | c: r.c,
}
}
func (r *TypeDef) WithFunction(function *Function) *TypeDef {
assertNotNil("function", function)
q := r.q.Select("withFunction")
q = q.Arg("function", function)
return &TypeDef{
q: q,
c: r.c,
}
}
func (r *TypeDef) WithKind(kind TypeDefKind) *TypeDef {
q := r.q.Select("withKind")
q = q.Arg("kind", kind)
return &TypeDef{
q: q,
c: r.c,
}
}
func (r *TypeDef) WithListOf(elementType *TypeDef) *TypeDef {
assertNotNil("elementType", elementType)
q := r.q.Select("withListOf")
q = q.Arg("elementType", elementType)
return &TypeDef{
q: q,
c: r.c,
}
}
type TypeDefWithObjectOpts struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | Description string
}
func (r *TypeDef) WithObject(name string, opts ...TypeDefWithObjectOpts) *TypeDef {
q := r.q.Select("withObject")
for i := len(opts) - 1; i >= 0; i-- {
if !querybuilder.IsZeroValue(opts[i].Description) {
q = q.Arg("description", opts[i].Description)
}
}
q = q.Arg("name", name)
return &TypeDef{
q: q,
c: r.c,
}
}
func (r *TypeDef) WithOptional(optional bool) *TypeDef {
q := r.q.Select("withOptional")
q = q.Arg("optional", optional)
return &TypeDef{
q: q,
c: r.c, |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | }
}
type CacheSharingMode string
func (CacheSharingMode) IsEnum() {}
const (
Locked CacheSharingMode = "LOCKED"
Private CacheSharingMode = "PRIVATE"
Shared CacheSharingMode = "SHARED"
)
type ImageLayerCompression string
func (ImageLayerCompression) IsEnum() {}
const (
Estargz ImageLayerCompression = "EStarGZ"
Gzip ImageLayerCompression = "Gzip"
Uncompressed ImageLayerCompression = "Uncompressed"
Zstd ImageLayerCompression = "Zstd"
)
type ImageMediaTypes string
func (ImageMediaTypes) IsEnum() {}
const (
Dockermediatypes ImageMediaTypes = "DockerMediaTypes"
Ocimediatypes ImageMediaTypes = "OCIMediaTypes"
)
type NetworkProtocol string
func (NetworkProtocol) IsEnum() {}
const ( |
closed | dagger/dagger | https://github.com/dagger/dagger | 3,284 | Use `withoutEntrypoint`, `withoutWorkdir`, `withoutUser` and `withoutDefaultArgs` to remove | Currently, passing nil or empty arguments to those function reinit the values.
It's not that explicit and clear.
It will make more API endpoints, but it's gonna be clearer. | https://github.com/dagger/dagger/issues/3284 | https://github.com/dagger/dagger/pull/6278 | 568d802bb892f1e074cf74cfce2a551989418964 | cd825bde699a0beb0adb5c2529da5469118a172b | 2022-10-07T15:00:07Z | go | 2023-12-19T13:11:01Z | sdk/go/dagger.gen.go | Tcp NetworkProtocol = "TCP"
Udp NetworkProtocol = "UDP"
)
type TypeDefKind string
func (TypeDefKind) IsEnum() {}
const (
Booleankind TypeDefKind = "BooleanKind"
Integerkind TypeDefKind = "IntegerKind"
Listkind TypeDefKind = "ListKind"
Objectkind TypeDefKind = "ObjectKind"
Stringkind TypeDefKind = "StringKind"
Voidkind TypeDefKind = "VoidKind"
) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | package templates
import (
"encoding/json"
"fmt"
"go/types"
"maps"
"strconv"
"strings"
. "github.com/dave/jennifer/jen"
"github.com/iancoleman/strcase"
)
const errorTypeName = "error"
var voidDef = Qual("dag", "TypeDef").Call().
Dot("WithKind").Call(Id("Voidkind")).
Dot("WithOptional").Call(Lit(true))
func (ps *parseState) parseGoFunc(receiverTypeName string, fn *types.Func) (*funcTypeSpec, error) {
spec := &funcTypeSpec{
name: fn.Name(),
}
funcDecl, err := ps.declForFunc(fn)
if err != nil {
return nil, fmt.Errorf("failed to find decl for method %s: %w", fn.Name(), err)
}
spec.doc = funcDecl.Doc.Text()
sig, ok := fn.Type().(*types.Signature)
if !ok {
return nil, fmt.Errorf("expected method to be a func, got %T", fn.Type())
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | spec.goType = sig
spec.argSpecs, err = ps.parseParamSpecs(fn)
if err != nil {
return nil, err
}
if receiverTypeName != "" {
ps.methods[receiverTypeName] = append(ps.methods[receiverTypeName], method{fn: fn, paramSpecs: spec.argSpecs})
}
results := sig.Results()
switch results.Len() {
case 0:
case 1:
result := results.At(0).Type()
if result.String() == errorTypeName {
spec.returnsError = true
break
}
spec.returnSpec, err = ps.parseGoTypeReference(result, nil)
if err != nil {
return nil, fmt.Errorf("failed to parse return type: %w", err)
}
case 2:
spec.returnsError = true
result := results.At(0).Type()
spec.returnSpec, err = ps.parseGoTypeReference(result, nil)
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | return nil, fmt.Errorf("failed to parse return type: %w", err)
}
default:
return nil, fmt.Errorf("method %s has too many return values", fn.Name())
}
return spec, nil
}
type funcTypeSpec struct {
name string
doc string
argSpecs []paramSpec
returnSpec ParsedType
returnsError bool
goType *types.Signature
}
var _ ParsedType = &funcTypeSpec{}
func (spec *funcTypeSpec) TypeDefCode() (*Statement, error) {
var fnReturnTypeDefCode *Statement
if spec.returnSpec == nil {
fnReturnTypeDefCode = voidDef
} else {
var err error
fnReturnTypeDefCode, err = spec.returnSpec.TypeDefCode()
if err != nil {
return nil, fmt.Errorf("failed to generate return type code: %w", err)
}
}
fnTypeDefCode := Qual("dag", "Function").Call(Lit(spec.name), Add(Line(), fnReturnTypeDefCode))
if spec.doc != "" {
fnTypeDefCode = dotLine(fnTypeDefCode, "WithDescription").Call(Lit(strings.TrimSpace(spec.doc))) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | }
for i, argSpec := range spec.argSpecs {
if i == 0 && argSpec.paramType.String() == contextTypename {
continue
}
argTypeDefCode, err := argSpec.typeSpec.TypeDefCode()
if err != nil {
return nil, fmt.Errorf("failed to generate arg type code: %w", err)
}
if argSpec.optional {
argTypeDefCode = argTypeDefCode.Dot("WithOptional").Call(Lit(true))
}
argOptsCode := []Code{}
if argSpec.description != "" {
argOptsCode = append(argOptsCode, Id("Description").Op(":").Lit(argSpec.description))
}
if argSpec.defaultValue != "" {
var jsonEnc string
if argSpec.typeSpec.GoType().String() == "string" {
enc, err := json.Marshal(argSpec.defaultValue)
if err != nil {
return nil, fmt.Errorf("failed to marshal default value: %w", err)
}
jsonEnc = string(enc)
} else {
jsonEnc = argSpec.defaultValue
}
argOptsCode = append(argOptsCode, Id("DefaultValue").Op(":").Id("JSON").Call(Lit(jsonEnc)))
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | argTypeDefArgCode := []Code{Lit(argSpec.graphqlName()), argTypeDefCode}
if len(argOptsCode) > 0 {
argTypeDefArgCode = append(argTypeDefArgCode, Id("FunctionWithArgOpts").Values(argOptsCode...))
}
fnTypeDefCode = dotLine(fnTypeDefCode, "WithArg").Call(argTypeDefArgCode...)
}
return fnTypeDefCode, nil
}
func (spec *funcTypeSpec) GoType() types.Type {
return spec.goType
}
func (spec *funcTypeSpec) GoSubTypes() []types.Type {
var types []types.Type
if spec.returnSpec != nil {
types = append(types, spec.returnSpec.GoSubTypes()...)
}
for _, argSpec := range spec.argSpecs {
if argSpec.typeSpec == nil {
continue
}
types = append(types, argSpec.typeSpec.GoSubTypes()...)
}
return types
}
func (ps *parseState) parseParamSpecs(fn *types.Func) ([]paramSpec, error) {
sig := fn.Type().(*types.Signature)
params := sig.Params()
if params.Len() == 0 { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | return nil, nil
}
specs := make([]paramSpec, 0, params.Len())
i := 0
if params.At(i).Type().String() == contextTypename {
spec, err := ps.parseParamSpecVar(params.At(i), "", "")
if err != nil {
return nil, err
}
specs = append(specs, spec)
i++
}
fnDecl, err := ps.declForFunc(fn)
if err != nil {
return nil, err
}
if i+1 == params.Len() {
param := params.At(i)
paramType, ok := asInlineStruct(param.Type())
if ok {
stype, ok := asInlineStructAst(fnDecl.Type.Params.List[i].Type)
if !ok {
return nil, fmt.Errorf("expected struct type for %s", param.Name())
}
parent := ¶mSpec{
name: params.At(i).Name(),
paramType: param.Type(),
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | paramFields := unpackASTFields(stype.Fields)
for f := 0; f < paramType.NumFields(); f++ {
spec, err := ps.parseParamSpecVar(paramType.Field(f), paramFields[f].Doc.Text(), paramFields[f].Comment.Text())
if err != nil {
return nil, err
}
spec.parent = parent
specs = append(specs, spec)
}
return specs, nil
}
}
paramFields := unpackASTFields(fnDecl.Type.Params)
for ; i < params.Len(); i++ {
docComment, lineComment := ps.commentForFuncField(fnDecl, paramFields, i)
spec, err := ps.parseParamSpecVar(params.At(i), docComment.Text(), lineComment.Text())
if err != nil {
return nil, err
}
if sig.Variadic() && i == params.Len()-1 {
spec.variadic = true
}
specs = append(specs, spec)
}
return specs, nil
}
func (ps *parseState) parseParamSpecVar(field *types.Var, docComment string, lineComment string) (paramSpec, error) {
if _, ok := field.Type().(*types.Struct); ok { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | return paramSpec{}, fmt.Errorf("nested structs are not supported")
}
paramType := field.Type()
baseType := paramType
for {
ptr, ok := baseType.(*types.Pointer)
if !ok {
break
}
baseType = ptr.Elem()
}
optional := false
defaultValue := ""
if named, ok := ps.isOptionalWrapper(baseType); ok {
typeArgs := named.TypeArgs()
if typeArgs.Len() != 1 {
return paramSpec{}, fmt.Errorf("optional type must have exactly one type argument")
}
optional = true
baseType = typeArgs.At(0)
for {
ptr, ok := baseType.(*types.Pointer)
if !ok {
break
}
baseType = ptr.Elem()
}
}
docPragmas, docComment := parsePragmaComment(docComment)
linePragmas, lineComment := parsePragmaComment(lineComment) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | comment := strings.TrimSpace(docComment)
if comment == "" {
comment = strings.TrimSpace(lineComment)
}
pragmas := make(map[string]string)
maps.Copy(pragmas, docPragmas)
maps.Copy(pragmas, linePragmas)
if v, ok := pragmas["default"]; ok {
defaultValue = v
}
if v, ok := pragmas["optional"]; ok {
if v == "" {
optional = true
} else {
optional, _ = strconv.ParseBool(v)
}
}
var typeSpec ParsedType
if paramType.String() != contextTypename {
var err error
typeSpec, err = ps.parseGoTypeReference(baseType, nil)
if err != nil {
return paramSpec{}, fmt.Errorf("failed to parse type reference: %w", err)
}
}
name := field.Name()
if name == "" {
name = typeSpec.GoType().String() |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/module_funcs.go | }
return paramSpec{
name: name,
paramType: paramType,
typeSpec: typeSpec,
optional: optional,
defaultValue: defaultValue,
description: comment,
}, nil
}
type paramSpec struct {
name string
description string
optional bool
variadic bool
defaultValue string
paramType types.Type
typeSpec ParsedType
parent *paramSpec
}
func (spec *paramSpec) graphqlName() string {
return strcase.ToLowerCamel(spec.name)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | package templates
import (
"fmt"
"go/ast"
"go/token"
"go/types"
"os"
"path/filepath"
"regexp"
"runtime/debug"
"sort"
"strings"
. "github.com/dave/jennifer/jen"
"github.com/iancoleman/strcase"
"golang.org/x/tools/go/packages"
)
const (
daggerGenFilename = "dagger.gen.go"
contextTypename = "context.Context"
constructorFuncName = "New"
)
/* |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | moduleMainSrc generates the source code of the main func for Dagger Module code using the Go SDK.
The overall idea is that users just need to create a struct with the same name as their Module and then
add methods to that struct to implement their Module. Methods on that struct become Functions.
They are also free to return custom objects from Functions, which themselves may have methods that become
Functions too. However, only the "top-level" Module struct's Functions will be directly invokable.
This is essentially just the GraphQL execution model.
The implementation works by parsing the user's code and generating a main func that reads function call inputs
from the Engine, calls the relevant function and returns the result. The generated code is mostly a giant switch/case
on the object+function name, with each case doing json deserialization of the input arguments and calling the actual
Go function.
*/
func (funcs goTemplateFuncs) moduleMainSrc() (string, error) {
defer func() {
if r := recover(); r != nil {
fmt.Fprintf(os.Stderr, "internal error during module code generation: %v\n", r)
debug.PrintStack()
panic(r)
}
}()
if funcs.modulePkg == nil {
return `func main() { panic("no code yet") }`, nil
}
ps := &parseState{
pkg: funcs.modulePkg,
fset: funcs.moduleFset, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | methods: make(map[string][]method),
moduleName: funcs.module.Name,
}
pkgScope := funcs.modulePkg.Types.Scope()
objFunctionCases := map[string][]Code{}
createMod := Qual("dag", "CurrentModule").Call()
objs := []types.Object{}
for _, name := range pkgScope.Names() {
obj := pkgScope.Lookup(name)
if obj == nil {
continue
}
objs = append(objs, obj)
}
sort.Slice(objs, func(i, j int) bool {
return objs[i].Pos() < objs[j].Pos()
})
tps := []types.Type{}
for _, obj := range objs {
fn, isFn := obj.(*types.Func)
if isFn && fn.Name() == constructorFuncName {
ps.constructor = fn
continue
}
tps = append(tps, obj.Type())
}
added := map[string]struct{}{} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | topLevel := true
for len(tps) != 0 {
var nextTps []types.Type
for _, tp := range tps {
named, isNamed := tp.(*types.Named)
if !isNamed {
continue
}
obj := named.Obj()
if obj.Pkg() != funcs.modulePkg.Types {
continue
}
if !obj.Exported() {
if !topLevel {
return "", fmt.Errorf("cannot code-generate unexported type %s", obj.Name())
}
continue
}
strct, isStruct := named.Underlying().(*types.Struct)
if !isStruct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | continue
}
if _, ok := added[obj.Name()]; ok {
continue
}
objTypeSpec, err := ps.parseGoStruct(strct, named)
if err != nil {
return "", err
}
if objTypeSpec == nil {
continue
}
if err := ps.fillObjectFunctionCases(named, objFunctionCases); err != nil {
return "", fmt.Errorf("failed to generate function cases for %s: %w", obj.Name(), err)
}
if topLevel && !ps.isMainModuleObject(obj.Name()) {
continue
}
objTypeDefCode, err := objTypeSpec.TypeDefCode()
if err != nil {
return "", fmt.Errorf("failed to generate type def code for %s: %w", obj.Name(), err)
}
createMod = dotLine(createMod, "WithObject").Call(Add(Line(), objTypeDefCode))
added[obj.Name()] = struct{}{} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | nextTps = append(nextTps, objTypeSpec.GoSubTypes()...)
}
tps, nextTps = nextTps, nil
topLevel = false
}
return strings.Join([]string{mainSrc, invokeSrc(objFunctionCases, createMod)}, "\n"), nil
}
func dotLine(a *Statement, id string) *Statement { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | return a.Op(".").Line().Id(id)
}
const (
mainSrc = `func main() {
ctx := context.Background()
fnCall := dag.CurrentFunctionCall()
parentName, err := fnCall.ParentName(ctx)
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
fnName, err := fnCall.Name(ctx)
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
parentJson, err := fnCall.Parent(ctx)
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | fnArgs, err := fnCall.InputArgs(ctx)
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
inputArgs := map[string][]byte{}
for _, fnArg := range fnArgs {
argName, err := fnArg.Name(ctx)
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
argValue, err := fnArg.Value(ctx)
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
inputArgs[argName] = []byte(argValue)
}
result, err := invoke(ctx, []byte(parentJson), parentName, fnName, inputArgs)
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
resultBytes, err := json.Marshal(result)
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
_, err = fnCall.ReturnValue(ctx, JSON(resultBytes)) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
}
`
parentJSONVar = "parentJSON"
parentNameVar = "parentName"
fnNameVar = "fnName"
inputArgsVar = "inputArgs"
invokeFuncName = "invoke"
)
func invokeSrc(objFunctionCases map[string][]Code, createMod Code) string {
objCases := []Code{}
for objName, functionCases := range objFunctionCases {
objCases = append(objCases, Case(Lit(objName)).Block(Switch(Id(fnNameVar)).Block(functionCases...)))
}
objCases = append(objCases, Case(Lit("")).Block(
Return(createMod, Nil()),
))
objCases = append(objCases, Default().Block(
Return(Nil(), Qual("fmt", "Errorf").Call(Lit("unknown object %s"), Id(parentNameVar))),
))
objSwitch := Switch(Id(parentNameVar)).Block(objCases...)
invokeFunc := Func().Id(invokeFuncName).Params( |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | Id("ctx").Qual("context", "Context"),
Id(parentJSONVar).Index().Byte(),
Id(parentNameVar).String(),
Id(fnNameVar).String(),
Id(inputArgsVar).Map(String()).Index().Byte(),
).Params(
Id("_").Id("any"),
Id("err").Error(),
).Block(objSwitch)
return fmt.Sprintf("%#v", invokeFunc)
}
func renderNameOrStruct(t types.Type) string {
if ptr, ok := t.(*types.Pointer); ok {
return "*" + renderNameOrStruct(ptr.Elem())
}
if sl, ok := t.(*types.Slice); ok {
return "[]" + renderNameOrStruct(sl.Elem())
}
if st, ok := t.(*types.Struct); ok {
result := "struct {\n"
for i := 0; i < st.NumFields(); i++ {
if !st.Field(i).Embedded() {
result += st.Field(i).Name() + " "
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | result += renderNameOrStruct(st.Field(i).Type())
if tag := st.Tag(i); tag != "" {
result += " `" + tag + "`"
}
result += "\n"
}
result += "}"
return result
}
if named, ok := t.(*types.Named); ok {
base := named.Obj().Name()
if typeArgs := named.TypeArgs(); typeArgs.Len() > 0 {
base += "["
for i := 0; i < typeArgs.Len(); i++ {
if i > 0 {
base += ", "
}
base += renderNameOrStruct(typeArgs.At(i))
}
base += "]"
}
return base
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | return t.String()
}
var checkErrStatement = If(Err().Op("!=").Nil()).Block(
Qual("fmt", "Println").Call(Err().Dot("Error").Call()),
Qual("os", "Exit").Call(Lit(2)),
)
func (ps *parseState) fillObjectFunctionCases(type_ types.Type, cases map[string][]Code) error {
var objName string
switch x := type_.(type) {
case *types.Pointer:
return ps.fillObjectFunctionCases(x.Elem(), cases)
case *types.Named:
objName = x.Obj().Name()
default:
return nil
}
if existingCases := cases[objName]; len(existingCases) > 0 {
return nil
}
hasConstructor := ps.isMainModuleObject(objName) && ps.constructor != nil
methods := ps.methods[objName]
if len(methods) == 0 && !hasConstructor {
return nil
}
for _, method := range methods {
fnName, sig := method.fn.Name(), method.fn.Type().(*types.Signature) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | if err := ps.fillObjectFunctionCase(objName, fnName, fnName, sig, method.paramSpecs, cases); err != nil {
return err
}
}
if hasConstructor {
sig, ok := ps.constructor.Type().(*types.Signature)
if !ok {
return fmt.Errorf("expected %s to be a function, got %T", constructorFuncName, ps.constructor.Type())
}
paramSpecs, err := ps.parseParamSpecs(ps.constructor)
if err != nil {
return fmt.Errorf("failed to parse %s function: %w", constructorFuncName, err)
}
results := sig.Results()
if results.Len() == 0 {
return fmt.Errorf("%s must return a value", constructorFuncName)
}
resultType := results.At(0).Type()
if ptrType, ok := resultType.(*types.Pointer); ok {
resultType = ptrType.Elem()
}
namedType, ok := resultType.(*types.Named)
if !ok {
return fmt.Errorf("%s must return the main module object %q", constructorFuncName, objName)
}
if namedType.Obj().Name() != objName {
return fmt.Errorf("%s must return the main module object %q", constructorFuncName, objName)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | if err := ps.fillObjectFunctionCase(objName, ps.constructor.Name(), "", sig, paramSpecs, cases); err != nil {
return err
}
}
cases[objName] = append(cases[objName], Default().Block(
Return(Nil(), Qual("fmt", "Errorf").Call(Lit("unknown function %s"), Id(fnNameVar))),
))
return nil
}
func (ps *parseState) fillObjectFunctionCase(
objName string,
fnName string,
caseName string,
sig *types.Signature,
paramSpecs []paramSpec,
cases map[string][]Code,
) error {
statements := []Code{}
parentVarName := "parent"
statements = append(statements,
Var().Id(parentVarName).Id(objName),
Err().Op("=").Qual("json", "Unmarshal").Call(Id(parentJSONVar), Op("&").Id(parentVarName)),
checkErrStatement,
)
var fnCallArgs []Code
if sig.Recv() != nil {
fnCallArgs = []Code{Op("&").Id(parentVarName)}
}
vars := map[string]struct{}{} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | for i, spec := range paramSpecs {
if i == 0 && spec.paramType.String() == contextTypename {
fnCallArgs = append(fnCallArgs, Id("ctx"))
continue
}
var varName string
var varType types.Type
var target *Statement
if spec.parent == nil {
varName = strcase.ToLowerCamel(spec.name)
varType = spec.paramType
target = Id(varName)
} else {
varName = spec.parent.name
varType = spec.parent.paramType
target = Id(spec.parent.name).Dot(spec.name)
}
if _, ok := vars[varName]; !ok {
vars[varName] = struct{}{} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | tp := varType
access := Id(varName)
tp2, access2 := findOptsAccessPattern(varType, Id(varName))
_, applyAccessPattern := tp2.(*types.Struct)
if !applyAccessPattern {
_, applyAccessPattern = ps.isOptionalWrapper(tp2)
}
if applyAccessPattern {
tp = tp2
access = access2
}
statements = append(statements, Var().Id(varName).Id(renderNameOrStruct(tp)))
if spec.variadic {
fnCallArgs = append(fnCallArgs, access.Op("..."))
} else {
fnCallArgs = append(fnCallArgs, access)
}
}
statements = append(statements,
If(Id(inputArgsVar).Index(Lit(spec.graphqlName())).Op("!=").Nil()).Block(
Err().Op("=").Qual("json", "Unmarshal").Call(
Index().Byte().Parens(Id(inputArgsVar).Index(Lit(spec.graphqlName()))),
Op("&").Add(target),
),
checkErrStatement,
))
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | results := sig.Results()
var callStatement *Statement
if sig.Recv() != nil {
callStatement = Parens(Op("*").Id(objName)).Dot(fnName).Call(fnCallArgs...)
} else {
callStatement = Id(fnName).Call(fnCallArgs...)
}
switch results.Len() {
case 2:
if results.At(1).Type().String() != errorTypeName {
return fmt.Errorf("second return value must be error, have %s", results.At(1).Type().String())
}
statements = append(statements, Return(callStatement))
cases[objName] = append(cases[objName], Case(Lit(caseName)).Block(statements...))
if err := ps.fillObjectFunctionCases(results.At(0).Type(), cases); err != nil {
return err
}
return nil
case 1:
if results.At(0).Type().String() == errorTypeName {
statements = append(statements, Return(Nil(), callStatement))
cases[objName] = append(cases[objName], Case(Lit(caseName)).Block(statements...))
} else {
statements = append(statements, Return(callStatement, Nil()))
cases[objName] = append(cases[objName], Case(Lit(caseName)).Block(statements...))
if err := ps.fillObjectFunctionCases(results.At(0).Type(), cases); err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | return err
}
}
return nil
case 0:
statements = append(statements,
callStatement,
Return(Nil(), Nil()))
cases[objName] = append(cases[objName], Case(Lit(caseName)).Block(statements...))
return nil
default:
return fmt.Errorf("unexpected number of results from function %s: %d", fnName, results.Len())
}
}
type parseState struct {
pkg *packages.Package
fset *token.FileSet
methods map[string][]method
moduleName string
constructor *types.Func
}
func (ps *parseState) isMainModuleObject(name string) bool {
return strcase.ToCamel(ps.moduleName) == strcase.ToCamel(name)
}
type method struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | fn *types.Func
paramSpecs []paramSpec
}
func (ps *parseState) astSpecForNamedType(namedType *types.Named) (*ast.TypeSpec, error) {
tokenFile := ps.fset.File(namedType.Obj().Pos())
if tokenFile == nil {
return nil, fmt.Errorf("no file for %s", namedType.Obj().Name())
}
for _, f := range ps.pkg.Syntax {
if ps.fset.File(f.Pos()) != tokenFile {
continue
}
for _, decl := range f.Decls {
genDecl, ok := decl.(*ast.GenDecl)
if !ok {
continue
}
for _, spec := range genDecl.Specs {
typeSpec, ok := spec.(*ast.TypeSpec)
if !ok { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | continue
}
if typeSpec.Name.Name == namedType.Obj().Name() {
if typeSpec.Doc == nil {
typeSpec.Doc = genDecl.Doc
}
return typeSpec, nil
}
}
}
}
return nil, fmt.Errorf("no decl for %s", namedType.Obj().Name())
}
func (ps *parseState) declForFunc(fnType *types.Func) (*ast.FuncDecl, error) {
var recv *types.Named
if signature, ok := fnType.Type().(*types.Signature); ok && signature.Recv() != nil {
tp := signature.Recv().Type()
for {
if p, ok := tp.(*types.Pointer); ok {
tp = p.Elem()
continue
}
break
}
recv, _ = tp.(*types.Named)
}
tokenFile := ps.fset.File(fnType.Pos())
if tokenFile == nil {
return nil, fmt.Errorf("no file for %s", fnType.Name())
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | for _, f := range ps.pkg.Syntax {
if ps.fset.File(f.Pos()) != tokenFile {
continue
}
for _, decl := range f.Decls {
fnDecl, ok := decl.(*ast.FuncDecl)
if !ok {
continue
}
if fnDecl.Name.Name != fnType.Name() {
continue
}
if recv != nil {
if len(fnDecl.Recv.List) != 1 {
continue
}
tp := fnDecl.Recv.List[0].Type
for {
if star, ok := tp.(*ast.StarExpr); ok {
tp = star.X
continue
}
break
}
ident, ok := tp.(*ast.Ident)
if !ok {
continue
}
if ident.Name != recv.Obj().Name() {
continue |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | }
}
return fnDecl, nil
}
}
return nil, fmt.Errorf("no decl for %s", fnType.Name())
}
func (ps *parseState) commentForFuncField(fnDecl *ast.FuncDecl, unpackedParams []*ast.Field, i int) (docComment *ast.CommentGroup, lineComment *ast.CommentGroup) {
pos := unpackedParams[i].Pos()
tokenFile := ps.fset.File(pos)
if tokenFile == nil {
return nil, nil
}
line := tokenFile.Line(pos)
allowDocComment := true
allowLineComment := true
if i == 0 {
fieldStartLine := tokenFile.Line(fnDecl.Type.Params.Pos())
if fieldStartLine == line || fieldStartLine == line-1 {
allowDocComment = false
}
} else {
prevArgLine := tokenFile.Line(unpackedParams[i-1].Pos())
if prevArgLine == line || prevArgLine == line-1 {
allowDocComment = false
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | }
if i+1 < len(fnDecl.Type.Params.List) {
nextArgLine := tokenFile.Line(unpackedParams[i+1].Pos())
if nextArgLine == line {
allowLineComment = false
}
} else {
fieldEndLine := tokenFile.Line(fnDecl.Type.Params.End())
if fieldEndLine == line {
allowLineComment = false
}
}
for _, f := range ps.pkg.Syntax {
if ps.fset.File(f.Pos()) != tokenFile {
continue
}
if allowDocComment {
npos := tokenFile.LineStart(tokenFile.Line(pos)) - 1
for _, comment := range f.Comments {
if comment.Pos() <= npos && npos <= comment.End() {
docComment = comment
break
}
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | }
if allowLineComment {
npos := tokenFile.LineStart(tokenFile.Line(pos)+1) - 1
for _, comment := range f.Comments {
if comment.Pos() <= npos && npos <= comment.End() {
lineComment = comment
break
}
}
}
}
return docComment, lineComment
}
func (ps *parseState) isDaggerGenerated(obj types.Object) bool {
tokenFile := ps.fset.File(obj.Pos())
return filepath.Base(tokenFile.Name()) == daggerGenFilename
}
func (ps *parseState) isOptionalWrapper(typ types.Type) (*types.Named, bool) {
named, ok := typ.(*types.Named)
if !ok {
return nil, false
}
if named.Obj().Name() == "Optional" && ps.isDaggerGenerated(named.Obj()) {
return named, true
}
return nil, false
}
func findOptsAccessPattern(t types.Type, access *Statement) (types.Type, *Statement) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | switch t := t.(type) {
case *types.Pointer:
t2, val := findOptsAccessPattern(t.Elem(), access)
return t2, Id("ptr").Call(val)
default:
return t, access
}
}
var pragmaCommentRegexp = regexp.MustCompile(`\+\s*(\S+?)(?:=(.+))?(?:\n|$)`)
func parsePragmaComment(comment string) (data map[string]string, rest string) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | data = map[string]string{}
lastEnd := 0
for _, v := range pragmaCommentRegexp.FindAllStringSubmatchIndex(comment, -1) {
var key, value string
if v[2] != -1 {
key = comment[v[2]:v[3]]
}
if v[4] != -1 {
value = comment[v[4]:v[5]]
}
data[key] = value
rest += comment[lastEnd:v[0]]
lastEnd = v[1]
}
rest += comment[lastEnd:]
return data, rest
}
func asInlineStruct(t types.Type) (*types.Struct, bool) {
switch t := t.(type) {
case *types.Pointer:
return asInlineStruct(t.Elem())
case *types.Struct:
return t, true
default:
return nil, false
}
}
func asInlineStructAst(t ast.Node) (*ast.StructType, bool) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | cmd/codegen/generator/go/templates/modules.go | switch t := t.(type) {
case *ast.StarExpr:
return asInlineStructAst(t.X)
case *ast.StructType:
return t, true
default:
return nil, false
}
}
func unpackASTFields(fields *ast.FieldList) []*ast.Field {
var unpacked []*ast.Field
for _, field := range fields.List {
if len(field.Names) == 0 {
unpacked = append(unpacked, field)
continue
}
for i, name := range field.Names {
field := *field
field.Names = []*ast.Ident{name}
if i != 0 {
field.Doc = nil
field.Comment = nil
}
unpacked = append(unpacked, &field)
}
}
return unpacked
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | package core
import (
"context"
_ "embed"
"encoding/json"
"fmt"
"go/format"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
"github.com/iancoleman/strcase"
"github.com/moby/buildkit/identity"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
"golang.org/x/sync/errgroup"
"dagger.io/dagger"
"github.com/dagger/dagger/cmd/codegen/introspection"
"github.com/dagger/dagger/core/modules"
)
func TestModuleGoInit(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Run("from scratch", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=bare", "--sdk=go"))
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.
With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
t.Run("reserved go.mod name", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=go", "--sdk=go"))
logGen(ctx, t, modGen.Directory(".")) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | out, err := modGen.
With(daggerQuery(`{go{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"go":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
t.Run("uses expected Go module name, camel-cases Dagger module name", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=My-Module", "--sdk=go"))
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.
With(daggerQuery(`{myModule{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"myModule":{"containerEcho":{"stdout":"hello\n"}}}`, out)
generated, err := modGen.File("go.mod").Contents(ctx)
require.NoError(t, err)
require.Contains(t, generated, "module main")
})
t.Run("creates go.mod beneath an existing go.mod if root points beneath it", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/go.mod", dagger.ContainerWithNewFileOpts{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Contents: "module example.com/test\n",
}).
WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{
Contents: "package foo\n",
}).
WithWorkdir("/work/ci").
With(daggerExec("mod", "init", "--name=beneathGoMod", "--sdk=go"))
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.
With(daggerQuery(`{beneathGoMod{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"beneathGoMod":{"containerEcho":{"stdout":"hello\n"}}}`, out)
t.Run("names Go module after Dagger module", func(t *testing.T) {
generated, err := modGen.File("go.mod").Contents(ctx)
require.NoError(t, err)
require.Contains(t, generated, "module main")
})
})
t.Run("respects existing go.mod", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithExec([]string{"go", "mod", "init", "example.com/test"}).
With(daggerExec("mod", "init", "--name=hasGoMod", "--sdk=go"))
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.
With(daggerQuery(`{hasGoMod{containerEcho(stringArg:"hello"){stdout}}}`)). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"hasGoMod":{"containerEcho":{"stdout":"hello\n"}}}`, out)
t.Run("preserves module name", func(t *testing.T) {
generated, err := modGen.File("go.mod").Contents(ctx)
require.NoError(t, err)
require.Contains(t, generated, "module example.com/test")
})
})
t.Run("respects parent go.mod if root points to it", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithExec([]string{"go", "mod", "init", "example.com/test"}).
WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{
Contents: "package foo\n",
}).
WithWorkdir("/work/child").
With(daggerExec("mod", "init", "--name=child", "--sdk=go", "--root=..")).
WithNewFile("/work/child/main.go", dagger.ContainerWithNewFileOpts{
Contents: `
package main
import "os"
type Child struct{}
func (m *Child) Root() *Directory {
wd, err := os.Getwd()
if err != nil {
panic(err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | }
return dag.Host().Directory(wd+"/..")
}
`,
})
generated := modGen.
With(daggerExec("mod", "sync")).
Directory(".")
logGen(ctx, t, generated)
out, err := modGen.
With(daggerQuery(`{child{root{entries}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"child":{"root":{"entries":["child","foo.go","go.mod","go.sum"]}}}`, out)
childEntries, err := generated.Entries(ctx)
require.NoError(t, err)
require.NotContains(t, childEntries, "go.mod")
t.Run("preserves parent module name", func(t *testing.T) {
generated, err := modGen.File("/work/go.mod").Contents(ctx)
require.NoError(t, err)
require.Contains(t, generated, "module example.com/test")
})
})
t.Run("respects existing go.mod even if root points to parent that has go.mod", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work"). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | WithExec([]string{"go", "mod", "init", "example.com/test"}).
WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{
Contents: "package foo\n",
}).
WithWorkdir("/work/child").
WithExec([]string{"go", "mod", "init", "my-mod"}).
With(daggerExec("mod", "init", "--name=child", "--sdk=go", "--root=..")).
WithNewFile("/work/child/main.go", dagger.ContainerWithNewFileOpts{
Contents: `
package main
import "os"
type Child struct{}
func (m *Child) Root() *Directory {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
return dag.Host().Directory(wd+"/..")
}
`,
})
generated := modGen.
With(daggerExec("mod", "sync")).
Directory(".")
logGen(ctx, t, generated)
out, err := modGen.
With(daggerQuery(`{child{root{entries}}}`)).
Stdout(ctx)
require.NoError(t, err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.JSONEq(t, `{"child":{"root":{"entries":["child","foo.go","go.mod"]}}}`, out)
childEntries, err := generated.Entries(ctx)
require.NoError(t, err)
require.Contains(t, childEntries, "go.mod")
require.Contains(t, childEntries, "go.sum")
})
t.Run("respects existing main.go", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: `
package main
type HasMainGo struct {}
func (m *HasMainGo) Hello() string { return "Hello, world!" }
`,
}).
With(daggerExec("mod", "init", "--name=hasMainGo", "--sdk=go"))
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.
With(daggerQuery(`{hasMainGo{hello}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"hasMainGo":{"hello":"Hello, world!"}}`, out)
})
t.Run("respects existing main.go even if it uses types not generated yet", func(t *testing.T) {
t.Parallel() |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: `
package main
type HasDaggerTypes struct {}
func (m *HasDaggerTypes) Hello() *Container {
return dag.Container().
From("` + alpineImage + `").
WithExec([]string{"echo", "Hello, world!"})
}
`,
}).
With(daggerExec("mod", "init", "--name=hasDaggerTypes", "--sdk=go"))
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.
With(daggerQuery(`{hasDaggerTypes{hello{stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"hasDaggerTypes":{"hello":{"stdout":"Hello, world!\n"}}}`, out)
})
t.Run("respects existing package without creating main.go", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/notmain.go", dagger.ContainerWithNewFileOpts{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Contents: `package main
type HasNotMainGo struct {}
func (m *HasNotMainGo) Hello() string { return "Hello, world!" }
`,
}).
With(daggerExec("mod", "init", "--name=hasNotMainGo", "--sdk=go"))
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.
With(daggerQuery(`{hasNotMainGo{hello}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"hasNotMainGo":{"hello":"Hello, world!"}}`, out)
})
}
func TestModulePythonInit(t *testing.T) {
t.Run("from scratch", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=bare", "--sdk=python"))
out, err := modGen.
With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
t.Run("with different root", func(t *testing.T) {
t.Parallel() |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/child").
With(daggerExec("mod", "init", "--name=bare", "--sdk=python", "--root=.."))
out, err := modGen.
With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
t.Run("respects existing pyproject.toml", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("pyproject.toml", dagger.ContainerWithNewFileOpts{
Contents: `[project]
name = "has-pyproject"
version = "0.0.0"
`,
}).
With(daggerExec("mod", "init", "--name=hasPyproject", "--sdk=python"))
out, err := modGen.
With(daggerQuery(`{hasPyproject{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"hasPyproject":{"containerEcho":{"stdout":"hello\n"}}}`, out)
t.Run("preserves module name", func(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | generated, err := modGen.File("pyproject.toml").Contents(ctx)
require.NoError(t, err)
require.Contains(t, generated, `name = "has-pyproject"`)
})
})
t.Run("respects existing main.py", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/src/main/__init__.py", dagger.ContainerWithNewFileOpts{
Contents: "from . import notmain\n",
}).
WithNewFile("/work/src/main/notmain.py", dagger.ContainerWithNewFileOpts{
Contents: `from dagger import function
@function
def hello() -> str:
return "Hello, world!"
`,
}).
With(daggerExec("mod", "init", "--name=hasMainPy", "--sdk=python"))
out, err := modGen.
With(daggerQuery(`{hasMainPy{hello}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"hasMainPy":{"hello":"Hello, world!"}}`, out)
})
}
func TestModuleInitLICENSE(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Run("bootstraps Apache-2.0 LICENSE file if none found", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=licensed-to-ill", "--sdk=go"))
content, err := modGen.File("LICENSE").Contents(ctx)
require.NoError(t, err)
require.Contains(t, content, "Apache License, Version 2.0")
})
t.Run("creates LICENSE file in the directory specified by -m", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "-m", "./mymod", "--name=licensed-to-ill", "--sdk=go"))
content, err := modGen.File("mymod/LICENSE").Contents(ctx)
require.NoError(t, err)
require.Contains(t, content, "Apache License, Version 2.0")
})
t.Run("does not bootstrap LICENSE file if it exists in the parent dir", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/LICENSE", dagger.ContainerWithNewFileOpts{
Contents: "doesnt matter",
}).
WithWorkdir("/work/sub").
With(daggerExec("mod", "init", "--name=licensed-to-ill", "--sdk=go"))
_, err := modGen.File("LICENSE").Contents(ctx)
require.Error(t, err)
})
t.Run("bootstraps a LICENSE file when requested, even if it exists in the parent dir", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/LICENSE", dagger.ContainerWithNewFileOpts{
Contents: "doesnt matter",
}).
WithWorkdir("/work/sub").
With(daggerExec("mod", "init", "--name=licensed-to-ill", "--sdk=go", "--license=MIT"))
content, err := modGen.File("LICENSE").Contents(ctx)
require.NoError(t, err)
require.Contains(t, content, "MIT License")
})
}
func TestModuleGit(t *testing.T) {
t.Parallel()
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
gitignores []string
}
for _, tc := range []testCase{
{
sdk: "go",
gitignores: []string{
"/dagger.gen.go\n",
"/querybuilder/\n",
},
},
{
sdk: "python",
gitignores: []string{
"/sdk\n",
},
},
{
sdk: "typescript",
gitignores: []string{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | "/sdk\n",
"/node_modules\n",
},
},
} {
tc := tc
t.Run(fmt.Sprintf("module %s git", tc.sdk), func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := goGitBase(t, c).
With(daggerExec("mod", "init", "--name=bare", "--sdk="+tc.sdk))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.
With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out)
t.Run("configures .gitignore", func(t *testing.T) {
ignore, err := modGen.File(".gitignore").Contents(ctx)
require.NoError(t, err)
for _, gitignore := range tc.gitignores {
require.Contains(t, ignore, gitignore)
}
})
})
}
}
func TestModuleGoGitRemovesIgnored(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
committedModGen := goGitBase(t, c).
With(daggerExec("mod", "init", "--name=bare", "--sdk=go")).
WithExec([]string{"rm", ".gitignore"}).
WithExec([]string{"mkdir", "./internal"}).
WithExec([]string{"cp", "-a", "./querybuilder", "./internal/querybuilder"}).
WithExec([]string{"git", "add", "."}).
WithExec([]string{"git", "commit", "-m", "init with generated files"})
changedAfterSync, err := committedModGen.
With(daggerExec("mod", "sync")).
WithExec([]string{"git", "diff"}).
WithExec([]string{"git", "status", "--short"}).
Stdout(ctx)
require.NoError(t, err)
t.Logf("changed after sync:\n%s", changedAfterSync)
require.Contains(t, changedAfterSync, "D dagger.gen.go\n")
require.Contains(t, changedAfterSync, "D querybuilder/marshal.go\n")
require.Contains(t, changedAfterSync, "D querybuilder/querybuilder.go\n")
require.Contains(t, changedAfterSync, "D internal/querybuilder/marshal.go\n")
require.Contains(t, changedAfterSync, "D internal/querybuilder/querybuilder.go\n")
}
func TestModulePythonGitRemovesIgnored(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
committedModGen := goGitBase(t, c).
With(daggerExec("mod", "init", "--name=bare", "--sdk=python")).
WithExec([]string{"rm", ".gitignore"}).
WithExec([]string{"git", "add", "."}).
WithExec([]string{"git", "commit", "-m", "init with generated files"})
changedAfterSync, err := committedModGen.
With(daggerExec("mod", "sync")).
WithExec([]string{"git", "diff"}).
WithExec([]string{"git", "status", "--short"}).
Stdout(ctx)
require.NoError(t, err)
t.Logf("changed after sync:\n%s", changedAfterSync)
require.Contains(t, changedAfterSync, "D sdk/pyproject.toml\n")
require.Contains(t, changedAfterSync, "D sdk/src/dagger/__init__.py\n")
}
func TestModuleTypescriptGitRemovesIgnored(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
committedModGen := goGitBase(t, c).
With(daggerExec("mod", "init", "--name=bare", "--sdk=typescript")).
WithExec([]string{"rm", ".gitignore"}).
WithExec([]string{"git", "add", "."}).
WithExec([]string{"git", "commit", "-m", "init with generated files"})
changedAfterSync, err := committedModGen.
With(daggerExec("mod", "sync")).
WithExec([]string{"git", "diff"}).
WithExec([]string{"git", "status", "--short"}).
Stdout(ctx)
require.NoError(t, err)
t.Logf("changed after sync:\n%s", changedAfterSync)
require.Contains(t, changedAfterSync, "D sdk/index.ts\n")
require.Contains(t, changedAfterSync, "D sdk/entrypoint/entrypoint.ts\n")
}
var goSignatures string
func TestModuleGoSignatures(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: goSignatures,
})
logGen(ctx, t, modGen.Directory("."))
t.Run("func Hello() string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{hello}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"hello":"hello"}}`, out)
})
t.Run("func Echo(string) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echo(msg: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echo":"hello...hello...hello..."}}`, out)
})
t.Run("func EchoPointer(*string) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoPointer(msg: "hello")}}`)).Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoPointer":"hello...hello...hello..."}}`, out)
})
t.Run("func EchoPointerPointer(**string) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoPointerPointer(msg: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoPointerPointer":"hello...hello...hello..."}}`, out)
})
t.Run("func EchoOptional(string) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptional(msg: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptional":"hello...hello...hello..."}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptional}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptional":"default...default...default..."}}`, out)
})
t.Run("func EchoOptionalPointer(string) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptionalPointer(msg: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptionalPointer":"hello...hello...hello..."}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptionalPointer}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptionalPointer":"default...default...default..."}}`, out)
})
t.Run("func EchoOptionalSlice([]string) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptionalSlice(msg: ["hello", "there"])}}`)).Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptionalSlice":"hello+there...hello+there...hello+there..."}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptionalSlice}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptionalSlice":"foobar...foobar...foobar..."}}`, out)
})
t.Run("func Echoes([]string) []string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoes(msgs: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoes":["hello...hello...hello..."]}}`, out)
})
t.Run("func EchoesVariadic(...string) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoesVariadic(msgs: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoesVariadic":"hello...hello...hello..."}}`, out)
})
t.Run("func HelloContext(context.Context) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{helloContext}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"helloContext":"hello context"}}`, out)
})
t.Run("func EchoContext(context.Context, string) string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoContext(msg: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoContext":"ctx.hello...ctx.hello...ctx.hello..."}}`, out)
}) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Run("func HelloStringError() (string, error)", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{helloStringError}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"helloStringError":"hello i worked"}}`, out)
})
t.Run("func HelloVoid()", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{helloVoid}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"helloVoid":null}}`, out)
})
t.Run("func HelloVoidError() error", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{helloVoidError}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"helloVoidError":null}}`, out)
})
t.Run("func EchoOpts(string, string, int) error", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOpts(msg: "hi")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOpts":"hi"}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOpts(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOpts":"hi!hi!"}}`, out)
})
t.Run("func EchoOptsInline(struct{string, string, int}) error", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptsInline(msg: "hi")}}`)).Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsInline":"hi"}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptsInline(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsInline":"hi!hi!"}}`, out)
})
t.Run("func EchoOptsInlinePointer(*struct{string, string, int}) error", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptsInlinePointer(msg: "hi")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsInlinePointer":"hi"}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptsInlinePointer(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsInlinePointer":"hi!hi!"}}`, out)
})
t.Run("func EchoOptsInlineCtx(ctx, struct{string, string, int}) error", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptsInlineCtx(msg: "hi")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsInlineCtx":"hi"}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptsInlineCtx(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsInlineCtx":"hi!hi!"}}`, out)
})
t.Run("func EchoOptsInlineTags(struct{string, string, int}) error", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptsInlineTags(msg: "hi")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsInlineTags":"hi"}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptsInlineTags(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsInlineTags":"hi!hi!"}}`, out)
})
t.Run("func EchoOptsPragmas(string, string, int) error", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptsPragmas(msg: "hi")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptsPragmas":"hi...hi...hi..."}}`, out)
})
}
var tsSignatures string
func TestModuleTypescriptSignatures(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=typescript")).
WithNewFile("src/index.ts", dagger.ContainerWithNewFileOpts{
Contents: tsSignatures,
})
t.Run("hello(): string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{hello}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"hello":"hello"}}`, out)
})
t.Run("echoes(msgs: string[]): string[]", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoes(msgs: "hello")}}`)).Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoes":["hello...hello...hello..."]}}`, out)
})
t.Run("echoOptional(msg = 'default'): string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptional(msg: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptional":"hello...hello...hello..."}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptional}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptional":"default...default...default..."}}`, out)
})
t.Run("echoesVariadic(...msgs: string[]): string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoesVariadic(msgs: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoesVariadic":"hello...hello...hello..."}}`, out)
})
t.Run("echo(msg: string): string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echo(msg: "hello")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echo":"hello...hello...hello..."}}`, out)
})
t.Run("echoOptionalSlice(msg = ['foobar']): string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOptionalSlice(msg: ["hello", "there"])}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptionalSlice":"hello+there...hello+there...hello+there..."}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOptionalSlice}}`)).Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOptionalSlice":"foobar...foobar...foobar..."}}`, out)
})
t.Run("helloVoid(): void", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{helloVoid}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"helloVoid":null}}`, out)
})
t.Run("echoOpts(msg: string, suffix: string = '', times: number = 1): string", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(`{minimal{echoOpts(msg: "hi")}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOpts":"hi"}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{echoOpts(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"echoOpts":"hi!hi!"}}`, out)
})
}
func TestModuleGoSignaturesBuiltinTypes(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import "context"
type Minimal struct {} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | func (m *Minimal) Read(ctx context.Context, dir Directory) (string, error) {
return dir.File("foo").Contents(ctx)
}
func (m *Minimal) ReadPointer(ctx context.Context, dir *Directory) (string, error) {
return dir.File("foo").Contents(ctx)
}
func (m *Minimal) ReadSlice(ctx context.Context, dir []Directory) (string, error) {
return dir[0].File("foo").Contents(ctx)
}
func (m *Minimal) ReadVariadic(ctx context.Context, dir ...Directory) (string, error) {
return dir[0].File("foo").Contents(ctx)
}
func (m *Minimal) ReadOptional(ctx context.Context, dir Optional[Directory]) (string, error) {
d, ok := dir.Get()
if ok {
return d.File("foo").Contents(ctx)
}
return "", nil
}
`,
})
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.With(daggerQuery(`{directory{withNewFile(path: "foo", contents: "bar"){id}}}`)).Stdout(ctx)
require.NoError(t, err)
dirID := gjson.Get(out, "directory.withNewFile.id").String()
t.Run("func Read(ctx, Directory) (string, error)", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{read(dir: "%s")}}`, dirID))).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"read":"bar"}}`, out) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | })
t.Run("func ReadPointer(ctx, *Directory) (string, error)", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{readPointer(dir: "%s")}}`, dirID))).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"readPointer":"bar"}}`, out)
})
t.Run("func ReadSlice(ctx, []Directory) (string, error)", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{readSlice(dir: ["%s"])}}`, dirID))).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"readSlice":"bar"}}`, out)
})
t.Run("func ReadVariadic(ctx, ...Directory) (string, error)", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{readVariadic(dir: ["%s"])}}`, dirID))).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"readVariadic":"bar"}}`, out)
})
t.Run("func ReadOptional(ctx, Optional[Directory]) (string, error)", func(t *testing.T) {
t.Parallel()
out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{readOptional(dir: "%s")}}`, dirID))).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"readOptional":"bar"}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{readOptional}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"readOptional":""}}`, out)
})
}
func TestModuleGoSignaturesUnexported(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
var logs safeBuffer
c, ctx := connect(t, dagger.WithLogOutput(&logs))
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Minimal struct {}
type Foo struct {}
type bar struct {}
func (m *Minimal) Hello(name string) string {
return name
}
func (f *Foo) Hello(name string) string {
return name
}
func (b *bar) Hello(name string) string {
return name
}
`,
})
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.With(inspectModule).Stdout(ctx)
require.NoError(t, err)
objs := gjson.Get(out, "host.directory.asModule.objects")
require.Equal(t, 1, len(objs.Array())) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | minimal := objs.Get(`0.asObject`)
require.Equal(t, "Minimal", minimal.Get("name").String())
modGen = c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Minimal struct {}
type Foo struct {}
type bar struct {}
func (m *Minimal) Hello(name string) Foo {
return Foo{}
}
func (f *Foo) Hello(name string) string {
return name
}
func (b *bar) Hello(name string) string {
return name
}
`,
})
logGen(ctx, t, modGen.Directory("."))
out, err = modGen.With(inspectModule).Stdout(ctx)
require.NoError(t, err)
objs = gjson.Get(out, "host.directory.asModule.objects")
require.Equal(t, 2, len(objs.Array()))
minimal = objs.Get(`0.asObject`)
require.Equal(t, "Minimal", minimal.Get("name").String())
foo := objs.Get(`1.asObject`) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.Equal(t, "MinimalFoo", foo.Get("name").String())
modGen = c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Minimal struct {}
type Foo struct {
Bar bar
}
type bar struct {}
func (m *Minimal) Hello(name string) Foo {
return Foo{}
}
func (f *Foo) Hello(name string) string {
return name
}
func (b *bar) Hello(name string) string {
return name
}
`,
})
logGen(ctx, t, modGen.Directory("."))
_, err = modGen.With(inspectModule).Stderr(ctx)
require.Error(t, err)
require.NoError(t, c.Close())
require.Contains(t, logs.String(), "cannot code-generate unexported type bar")
}
func TestModuleGoSignaturesMixMatch(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
var logs safeBuffer
c, ctx := connect(t, dagger.WithLogOutput(&logs))
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Minimal struct {}
func (m *Minimal) Hello(name string, opts struct{}, opts2 struct{}) string {
return name
}
`,
})
logGen(ctx, t, modGen.Directory("."))
_, err := modGen.With(daggerQuery(`{minimal{hello}}`)).Stdout(ctx)
require.Error(t, err)
require.NoError(t, c.Close())
require.Contains(t, logs.String(), "nested structs are not supported")
}
func TestModuleGoSignaturesNameConflict(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
var logs safeBuffer
c, ctx := connect(t, dagger.WithLogOutput(&logs))
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Minimal struct {
Foo Foo
Bar Bar |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Baz Baz
}
type Foo struct {}
type Bar struct {}
type Baz struct {}
func (m *Foo) Hello(name string) string {
return name
}
func (f *Bar) Hello(name string, name2 string) string {
return name + name2
}
func (b *Baz) Hello() (string, error) {
return "", nil
}
`,
})
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.With(inspectModule).Stdout(ctx)
require.NoError(t, err)
objs := gjson.Get(out, "host.directory.asModule.objects")
require.Equal(t, 4, len(objs.Array()))
obj := objs.Get(`0.asObject`)
require.Equal(t, "Minimal", obj.Get("name").String())
obj = objs.Get(`1.asObject`)
require.Equal(t, "MinimalFoo", obj.Get("name").String())
obj = objs.Get(`2.asObject`)
require.Equal(t, "MinimalBar", obj.Get("name").String())
obj = objs.Get(`3.asObject`)
require.Equal(t, "MinimalBaz", obj.Get("name").String())
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | var inspectModule = daggerQuery(`
query {
host {
directory(path: ".") {
asModule {
objects {
asObject {
name
description
functions {
name
description
args {
name
description
defaultValue
}
}
fields {
name
description
}
}
}
}
}
}
}
`)
func TestModuleGoDocs(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: goSignatures,
})
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.With(inspectModule).Stdout(ctx)
require.NoError(t, err)
obj := gjson.Get(out, "host.directory.asModule.objects.0.asObject")
require.Equal(t, "Minimal", obj.Get("name").String())
hello := obj.Get(`functions.#(name="hello")`)
require.Equal(t, "hello", hello.Get("name").String())
require.Empty(t, hello.Get("description").String())
require.Empty(t, hello.Get("args").Array())
echoOpts := obj.Get(`functions.#(name="echoOpts")`)
require.Equal(t, "echoOpts", echoOpts.Get("name").String())
require.Equal(t, "EchoOpts does some opts things", echoOpts.Get("description").String())
require.Len(t, echoOpts.Get("args").Array(), 3)
require.Equal(t, "msg", echoOpts.Get("args.0.name").String()) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.Equal(t, "the message to echo", echoOpts.Get("args.0.description").String())
require.Equal(t, "suffix", echoOpts.Get("args.1.name").String())
require.Equal(t, "String to append to the echoed message", echoOpts.Get("args.1.description").String())
require.Equal(t, "times", echoOpts.Get("args.2.name").String())
require.Equal(t, "Number of times to repeat the message", echoOpts.Get("args.2.description").String())
echoOpts = obj.Get(`functions.#(name="echoOptsInline")`)
require.Equal(t, "echoOptsInline", echoOpts.Get("name").String())
require.Equal(t, "EchoOptsInline does some opts things", echoOpts.Get("description").String())
require.Len(t, echoOpts.Get("args").Array(), 3)
require.Equal(t, "msg", echoOpts.Get("args.0.name").String())
require.Equal(t, "the message to echo", echoOpts.Get("args.0.description").String())
require.Equal(t, "suffix", echoOpts.Get("args.1.name").String())
require.Equal(t, "String to append to the echoed message", echoOpts.Get("args.1.description").String())
require.Equal(t, "times", echoOpts.Get("args.2.name").String())
require.Equal(t, "Number of times to repeat the message", echoOpts.Get("args.2.description").String())
echoOpts = obj.Get(`functions.#(name="echoOptsPragmas")`)
require.Equal(t, "echoOptsPragmas", echoOpts.Get("name").String())
require.Len(t, echoOpts.Get("args").Array(), 3)
require.Equal(t, "msg", echoOpts.Get("args.0.name").String())
require.Equal(t, "", echoOpts.Get("args.0.defaultValue").String())
require.Equal(t, "suffix", echoOpts.Get("args.1.name").String())
require.Equal(t, "String to append to the echoed message", echoOpts.Get("args.1.description").String())
require.Equal(t, "\"...\"", echoOpts.Get("args.1.defaultValue").String())
require.Equal(t, "times", echoOpts.Get("args.2.name").String())
require.Equal(t, "3", echoOpts.Get("args.2.defaultValue").String())
require.Equal(t, "Number of times to repeat the message", echoOpts.Get("args.2.description").String())
}
func TestModuleGoDocsEdgeCases(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
// Minimal is a thing
type Minimal struct {
// X is this
X, Y string // Y is not this
// +private
Z string
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | // some docs
func (m *Minimal) Hello(foo string, bar string,
// hello
baz string, qux string, x string, // lol
) string {
return foo + bar
}
func (m *Minimal) HelloMore(
// foo here
foo,
// bar here
bar string,
) string {
return foo + bar
}
func (m *Minimal) HelloMoreInline(opts struct{
// foo here
foo, bar string
}) string {
return opts.foo + opts.bar
}
func (m *Minimal) HelloAgain( // docs for helloagain
foo string,
bar string, // docs for bar
baz string,
) string {
return foo + bar
}
func (m *Minimal) HelloFinal(
foo string) string { // woops |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | return foo
}
`,
})
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.With(inspectModule).Stdout(ctx)
require.NoError(t, err)
obj := gjson.Get(out, "host.directory.asModule.objects.0.asObject")
require.Equal(t, "Minimal", obj.Get("name").String())
require.Equal(t, "Minimal is a thing", obj.Get("description").String())
hello := obj.Get(`functions.#(name="hello")`)
require.Equal(t, "hello", hello.Get("name").String())
require.Len(t, hello.Get("args").Array(), 5)
require.Equal(t, "foo", hello.Get("args.0.name").String())
require.Equal(t, "", hello.Get("args.0.description").String())
require.Equal(t, "bar", hello.Get("args.1.name").String())
require.Equal(t, "", hello.Get("args.1.description").String())
require.Equal(t, "baz", hello.Get("args.2.name").String())
require.Equal(t, "hello", hello.Get("args.2.description").String())
require.Equal(t, "qux", hello.Get("args.3.name").String())
require.Equal(t, "", hello.Get("args.3.description").String())
require.Equal(t, "x", hello.Get("args.4.name").String())
require.Equal(t, "lol", hello.Get("args.4.description").String())
hello = obj.Get(`functions.#(name="helloMore")`)
require.Equal(t, "helloMore", hello.Get("name").String())
require.Len(t, hello.Get("args").Array(), 2)
require.Equal(t, "foo", hello.Get("args.0.name").String())
require.Equal(t, "foo here", hello.Get("args.0.description").String())
require.Equal(t, "bar", hello.Get("args.1.name").String())
require.Equal(t, "bar here", hello.Get("args.1.description").String()) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | hello = obj.Get(`functions.#(name="helloMoreInline")`)
require.Equal(t, "helloMoreInline", hello.Get("name").String())
require.Len(t, hello.Get("args").Array(), 2)
require.Equal(t, "foo", hello.Get("args.0.name").String())
require.Equal(t, "foo here", hello.Get("args.0.description").String())
require.Equal(t, "bar", hello.Get("args.1.name").String())
require.Equal(t, "", hello.Get("args.1.description").String())
hello = obj.Get(`functions.#(name="helloAgain")`)
require.Equal(t, "helloAgain", hello.Get("name").String())
require.Len(t, hello.Get("args").Array(), 3)
require.Equal(t, "foo", hello.Get("args.0.name").String())
require.Equal(t, "", hello.Get("args.0.description").String())
require.Equal(t, "bar", hello.Get("args.1.name").String())
require.Equal(t, "docs for bar", hello.Get("args.1.description").String())
require.Equal(t, "baz", hello.Get("args.2.name").String())
require.Equal(t, "", hello.Get("args.2.description").String())
hello = obj.Get(`functions.#(name="helloFinal")`)
require.Equal(t, "helloFinal", hello.Get("name").String())
require.Len(t, hello.Get("args").Array(), 1)
require.Equal(t, "foo", hello.Get("args.0.name").String())
require.Equal(t, "", hello.Get("args.0.description").String())
require.Len(t, obj.Get(`fields`).Array(), 2)
prop := obj.Get(`fields.#(name="x")`)
require.Equal(t, "x", prop.Get("name").String())
require.Equal(t, "X is this", prop.Get("description").String())
prop = obj.Get(`fields.#(name="y")`)
require.Equal(t, "y", prop.Get("name").String())
require.Equal(t, "", prop.Get("description").String())
}
func TestModuleGoWeirdFields(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Z string
type Minimal struct {
// field with single (normal) name
W string
// field with multiple names
X, Y string
// field with no names
Z
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.