Repository navigation
Conversation
A dataclass or pydantic field with a default reached the caller as a required socket, so a graph that left it alone failed with a missing required input naming that field. - Mark a field optional when it declares a default or a default factory, in the pydantic, dataclass, and dynamic branches of `from_model`. - Read the factory's presence only, never calling it, so a field's default value is still copied only from a plain default. - Apply requiredness to namespace fields too, which carry no default value but may be omitted just the same. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Three of the new tests asserted the same thing twice in one function, once for a dataclass and once for a pydantic model, so a failure did not say which kind broke. - Parametrize them over the two model kinds, with `dataclass` and `pydantic` ids. - Build the default-factory models from a per-case factory, so each case asserts its own factory went uncalled. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #173 +/- ##
==========================================
+ Coverage 89.68% 89.77% +0.09%
==========================================
Files 81 81
Lines 8984 9069 +85
==========================================
+ Hits 8057 8142 +85
Misses 927 927 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A task taking a dataclass or a pydantic model as input refused to run unless the caller filled in every field, defaults included. Given
a caller who set only
nelecwas toldsettings.tot_magnetizationwas missing, andecutescaped the same complaint only because its default is notNone.SocketSpecAPI.from_modelcopied each field's default onto the child spec but never derived requiredness from it, someta.requiredkept itsTruedefault. The function-signature path and the TypedDict path already derive requiredness; the model paths now do too.Changes
from_modeldefault_factoryas a defaultsub: Optional[Sub] = Nonemay be omitted like any other; a namespace simply has no place to keep the default value, and its requiredness is the only thing that says the caller may skip it.Falserather than left asNone. If we left asNone,merge_metalets aTruebase survive it, andSocketMeta.to_dictomits it sofrom_dictrestores theTruedefault. OnlyFalsestates optionality in a way that survives a round tripNot covered
Three other paths still set a leaf default without touching requiredness:
namespace(b=(int, 5)),set_default, and the mapping default of a namespace parameter. They are outsidefrom_modeland therefore outside this fix; a downstream consumer that exempts defaulted sockets from its own missing-input check still needs that exemption for them.Closes #172