Repository navigation
fix: flow defaults no longer overwrite values the model set - #392
Open
markthomaschurch wants to merge 2 commits into
Open
markthomaschurch wants to merge 2 commits into
markthomaschurch wants to merge 2 commits into
Conversation
During process(), _apply_defaults() copies values from a dataflow's source and sink onto the dataflow and its data: protocol and ports, controls.isEncrypted, authenticatesDestination and checksDestinationRevocation, Data.isSourceEncryptedAtRest and isDestEncryptedAtRest, and levels. They are meant to fill in what the model left out. Before the move to pydantic (cfc38f8) attributes could only be set once, so _safeset() could only fill gaps; since then it is a plain setattr, and every default replaces the model's value. A flow declared as encrypted HTTPS on port 443 was evaluated as unencrypted with no protocol (false DE01, CR08 and similar findings), data explicitly not encrypted at rest was flipped to encrypted, and reports and diagrams showed the overwritten values. The example model's own protocols and ports (HTTP, MySQL, 80, 3306, ...) were replaced by "" and -1. Fill in only attributes that aren't set, using pydantic's model_fields_set (constructor arguments and assignments). A value filled in by a default counts as set, so the first default wins, as before the move to pydantic. The three identical _safeset() methods (Element, Controls, Data) now share one helper, base.set_default(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #391
The dataflow defaults applied by
TM.process()now fill in only the attributes a model left unset, instead of overwriting the ones it set, as they did before the move to pydantic (#320).pytm/base.py: newset_default(model, attr, value), which sets the attribute unless it's inmodel.model_fields_set(given to the constructor or assigned since), ignoring values the attribute doesn't accept. A value it fills in counts as set, so the first default wins, as before Refactor models to Pydantic #320.pytm/element.py,pytm/base.py(Controls),pytm/data.py: the three identical_safeset()methods use it.tests/test_flow_defaults.py(new): explicit values are kept on forward and response flows, on data and for levels, including explicit values equal to the type's default; unset values still come from the sink/source; a flow declared as encrypted HTTPS gets no DE01/CR08 finding. The seven tests with explicit values fail onmaster.pytest tests→ 279 passed (pydantic 2.12.5 and 2.14.3).🤖 Generated with Claude Code