Skip to content

A possible issue with not deepcopying job kwargs#860

Merged
utf merged 2 commits intomaterialsproject:mainfrom
vineetbansal:vb/job_kwargs_ref
Apr 13, 2026
Merged

A possible issue with not deepcopying job kwargs#860
utf merged 2 commits intomaterialsproject:mainfrom
vineetbansal:vb/job_kwargs_ref

Conversation

@vineetbansal
Copy link
Copy Markdown
Contributor

As we discovered when working towards another PR, mutating one job's config mutates all others created by that decorator. This is because the @job decorator keeps a reference to job_kwargs instead of deep-copying it. This may or may not be an issue, and may just need explicit documentation.

This PR introduces an xfail test to demonstrate this behavior. The solution suggested by @gpetretto which should solve this is:

--- a/src/jobflow/core/job.py
+++ b/src/jobflow/core/job.py
@@ -184,6 +184,7 @@ def job(
     --------
     Job, .Flow, .Response
     """
+    from copy import deepcopy

     def decorator(func):
         from functools import wraps
@@ -214,7 +215,7 @@ def job(
                         args = args[1:]

             return Job(
-                function=f, function_args=args, function_kwargs=kwargs, **job_kwargs
+                function=f, function_args=args, function_kwargs=kwargs, **deepcopy(job_kwargs)
             )

@utf utf merged commit e002ffb into materialsproject:main Apr 13, 2026
7 checks passed
@gpetretto
Copy link
Copy Markdown
Contributor

Sorry @vineetbansal, can you confirm that this was just the test to verify the bug and that the proposed solution has not been included in any other of your PRs? If that's the case I will open a PR with the proposed fix.

@vineetbansal
Copy link
Copy Markdown
Contributor Author

vineetbansal commented Apr 13, 2026

Hi @gpetretto - yes this is just to demonstrate the issue. The fix is not in this this PR or any other. You can add the fix to this PR and merge (removing the xfail) or let me know and I'll do so. Or we can close this PR if you're going to be opening up a new one.

@gpetretto
Copy link
Copy Markdown
Contributor

If you have the time to add this, it is fine with me. But if you are short on time let me know and I can also do that.

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.

3 participants