Skip to content

Fix module name conflicts with core types #6328

Closed

Description

@sipsma

Related discord question: https://discord.com/channels/707636530424053791/1190052885686407179/1190054150747213824

Right now a module that has the same name as a core type (e.g. Module, Container, etc.) will eventually result in an error. This is not only due to conflicts in the SDK code (depending on the SDK language) but ultimately also on the graphql schema level.

At a bare minimum, we should error out in dagger mod init if a module has a name that will result in a conflict. This is probably the right starting place.

Even better would be to handle this transparently so that even on the graphql schema level there's no possibility for conflicts like this. Namespacing doesn't fix this because the main module object is just the name of the module. The only way I can think of is to separate the names of the objects in the graphql schema and the names used by SDKs for codegen.

  • This is totally possible, but will require small-to-medium sized updates to every SDK's codegen logic
  • This can also be done in the future transparently, so doesn't need to be now or never

Activity

  1. added
    kind/bug
    on Dec 29, 2023
  2. self-assigned this
    on Feb 5, 2024
  3. added and removed
    kind/bug
    on May 31, 2024
  4. added
    area/engine
    and removed on Jul 6, 2024
  5. sipsma commented on Sep 20, 2024

    @sipsma
    ContributorAuthor

    This got hit in the real-world by @shykes while working on our CI due to a non-core dep being named Git.

    • The workaround of renaming the dep from git->coolgit in dagger.json worked as intended, which is okay but obviously not ideal or obvious.

    However the way it failed was interesting/concerning.

    His module, which had a dep named Git and thus overrode Query.git to be his dependency's implementation. The module then received an argument of type Directory whose dagql id included a call to the core Query.git implementation.

    When the module resolved the Directory, it ended up using Query.git from the dependency rather than core.

    The behavior here should have been that something in the ID specified which Query.git it referred to and called that.

    • Maybe the way to think about this is that when a module resolves an arg received from another caller module, that arg's dagql ID needs to be evaluated in the dagql server of the caller module?
    • We include the module digest inside dagql Calls, so there might be a lot of plumbing in place to do this already?
  6. added this to the next milestone on Sep 20, 2024
  7. added
    kind/bug
    on Sep 20, 2024
  8. sipsma commented on Sep 20, 2024

    @sipsma
    ContributorAuthor

    I'll throw this in the next milestone for now since it seems like a ticking time bomb in terms of user confusion, with the only saving grace being there's a relatively low-pain fix if you know what's happening (rename dependencies)

    cc @jedevc, just for your radar

  9. sipsma commented on Sep 21, 2024

    @sipsma
    ContributorAuthor

    Actually this gets a bit worse, in the github.com/shykes/git module itself the same conflict will happen (due to the fact that modules are served access to their own APIs)...

    That in particular is an additional layer of annoying to deal with. The only way I can think of is that when serving self APIs, we don't serve them under Query.<modname>, we instead always serve them at Query.self.

    • This would be aligned with the changes we need to make to codegen to support self calls in the API anyways, so might work out fine?
  10. jedevc commented on Apr 8, 2025

    @jedevc
    Contributor

    So a specific case came up in discord earlier: https://discord.com/channels/707636530424053791/1359007453907386368/1359179295532257411

    Take the following go module test:

    // main.go
    package main
    
    type Test struct{}
    
    type Env struct{}
    
    type Env2 struct{}
    
    func (m *Test) Test() *Env {
    	return &Env{}
    }
    
    func (m *Test) Test2() *Env2 {
    	return &Env2{}
    }

    If I try and run this module, I get:

    ❯ dagger call
    ✔ connect 0.2s
    ✘ load module 3.0s
    ! input: failed to get schema: failed to get schema for module "test": type "Env" is already defined by module "daggercore"
    │ ✔ finding module configuration 0.3s
    │ ✔ initializing module 2.8s
    │ ✘ inspecting module metadata 0.0s
    │ ! input: failed to get schema: failed to get schema for module "test": type "Env" is already defined by module "daggercore"
    

    This is confusing - because this should be namespaced! In fact, looking at the results of namespacing manually, we can see that Env2 gets correctly namespaced to TestEnv2, but that Env is skipped. This is because of the logic here:

    dagger/core/module.go

    Lines 484 to 492 in 06194e5

    // only namespace objects defined in this module
    _, ok, err := mod.Deps.ModTypeFor(ctx, typeDef)
    if err != nil {
    return fmt.Errorf("failed to get mod type for type def: %w", err)
    }
    if !ok {
    obj.Name = namespaceObject(obj.OriginalName, mod.Name(), mod.OriginalName)
    obj.SourceMap = mod.namespaceSourceMap(modPath, obj.SourceMap)
    }

    We should always namespace this top-level object - since it's being created by the user.

    However, it's not as simple as that - see the generated go code in invoke for this module:

    	case "":
    		return dag.Module().
    			WithObject(
    				dag.TypeDef().WithObject("Test", dagger.TypeDefWithObjectOpts{SourceMap: dag.SourceMap("main.go", 3, 6)}).
    					WithFunction(
    						dag.Function("Test",
    							dag.TypeDef().WithObject("Env")).
    							WithSourceMap(dag.SourceMap("main.go", 9, 1))).
    					WithFunction(
    						dag.Function("Test2",
    							dag.TypeDef().WithObject("Env2")).
    							WithSourceMap(dag.SourceMap("main.go", 13, 1)))).
    			WithObject(
    				dag.TypeDef().WithObject("Env", dagger.TypeDefWithObjectOpts{SourceMap: dag.SourceMap("main.go", 5, 6)})).
    			WithObject(
    				dag.TypeDef().WithObject("Env2", dagger.TypeDefWithObjectOpts{SourceMap: dag.SourceMap("main.go", 7, 6)})), nil

    So, while it's trivial to ensure that we namespace Env for the Module.WithObject call at the top-level, it then becomes unclear what the return type for Test should be when it's returning Env. At the moment, the API can't distinguish between Env declared in this module, and Env declared in the core API.

    It feels like we need a more complex API to deal with this here? As one idea, we actually know in each SDK whether a type is a generated type or not - we could attach that to WithObject, instead of automagically trying to determine it.

    One note, is that if I rename the type to TestEnv it actually works as well - since this skips the namespacing in the engine, since it's actually already namespaced:

    if rest := strings.TrimPrefix(objOriginalName, gqlObjectName(modOriginalName)); rest != objOriginalName {

  11. locked and limited conversation to collaborators on Mar 24, 2026
  12. converted this issue into a discussion #12401 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/enginearea/sdkkind/bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions