Skip to content

engine: fix +ignore pragma for constructors#11835

Open
matipan wants to merge 1 commit intodagger:mainfrom
matipan:fix-constructor-ignore-pragma
Open

engine: fix +ignore pragma for constructors#11835
matipan wants to merge 1 commit intodagger:mainfrom
matipan:fix-constructor-ignore-pragma

Conversation

@matipan
Copy link
Contributor

@matipan matipan commented Feb 10, 2026

Fixes #11750.


The issue is caused by a check on setCallInputs:

if len(arg.metadata.Ignore) > 0 && !arg.metadata.isContextual() { // contextual args already have ignore applied

In this context an argument is considered contextual if either the DefaultPath or DefaultAddress is set. If it is then setCallInputs will not go through the ignore process of directories. The problem: arguments that are contextual (they have a default path) but a user specified a value will not be loaded as part of the contextual loading and will also be ignored in this check. This means applyIgnoreOnDir will never run for them.

Looking into the code I found two potential fixes:

  1. Remove the isContextual check and apply ignore on all arguments. Great for simplicity, but it means we are going to run the applyIgnoreOnDir functions on truly contextual arguments twice.
  2. Mark contextual arguments only when they are 100% coming from the context directory and not from user inputs.

I went with the second option even though it required more code changes. I'm not 100% sure on the performance impact of running applyIgnoreOnDir twice for contextual args, but it felt wasteful.

As for the test: I created a separate test even though we already have a TestIgnore. This was mainly to keep the existing test clean given that it tests a wide range of cases but for function arguments only. Happy to merge them and look into potential improvements for them.

Tested the change with a dev engine and a module with the following code:

// ...
func New(
	// +defaultPath="."
	// +ignore=["**", "!dagger.json"]
	source *dagger.Directory,
) *NewMod {
	return &NewMod{
		Source: source,
	}
}

func (m *NewMod) TestSource(
	ctx context.Context,
) (string, error) {
	return dag.Container().
		From("alpine:latest").
		WithDirectory("/source", m.Source).
		WithExec([]string{"ls", "-lh", "/source"}).
		Stdout(ctx)
}

Specifying the arg using a dev engine vs v0.19.11:
2026-02-10_11-19

Not specifying the arg (using the context):
2026-02-10_11-21


AI disclosure

We don't really do or require this in the project, but given the buzz in social media I thought it would be worth disclosing the use of AI for this PR.

I used it as a guide to look into the code and it helped me understand how arguments are considered contextual, at which point they are loaded and ignored and what is the difference between constructor and function args. Once we found the bug, the code changes were also AI assisted but not vibe coded.

@matipan matipan requested review from marcosnils and sipsma February 10, 2026 14:23
@matipan matipan force-pushed the fix-constructor-ignore-pragma branch from 80f06c5 to e63aa32 Compare February 10, 2026 15:15
Copy link
Contributor

@sipsma sipsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we 100% sure that this was specific to constructors? I can't see anything in the diff that is specific to constructors, but might have missed something.

Asking because if the behavior of "explicit arg doesn't use ignore" was true for normal functions but false for constructors, then I totally agree we should make them consistent.

However, if the behavior today is that "explicit arg doesn't use ignore" for all functions, then I actually think it's pretty ambiguous whether that's correct or not. I can see cases where passing an explicit argument in place of your context dir:

  1. should NOT use the default ignores, i.e. I really want you to use the directory I give you
  2. should use the default ignores, i.e. don't make me manually type all that out again just because I'm overriding a path

It almost seems like something that should be possible to specify somehow when you pass the arg?

cc @shykes @kpenfound DX related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 The +ignore pragma is not always respected during module construction

2 participants