Repository navigation
Conversation
adrinjalali
left a comment
There was a problem hiding this comment.
Thanks @3urek4, good catch. The fix is right: with allowed_types=(_general.TupleNode,), a file declaring protocol 0–2 now goes through the same check as the current OperatorFuncNode. That includes a node coming back from the memo through __id__, since get_tree checks those too. I also checked that the new test fails for protocols 0, 1 and 2 without the change to _general_v2.py, and that the other old readers (dict/list/set in _general_v2.py, the generator in _numpy_v1) already check the same node types as their current versions. I agree no changelog entry is needed, since the #547 entry covers this.
I've left a few suggestions inline. They're about keeping the old and current readers from drifting apart again, since that's how this gap opened after #547/#551.
| state["attrs"], | ||
| load_context, | ||
| trusted=trusted, | ||
| allowed_types=(_general.TupleNode,), |
There was a problem hiding this comment.
This now repeats the current node's check by hand, and nothing keeps the two in step. A later PR that tightens allowed_types in skops.io._general.OperatorFuncNode, or moves another node into skops.io.old, could leave the old reader behind again.
It doesn't have to be fixed here, but one of these would help:
- a shared module-level constant, e.g.
_OPERATOR_ATTRS_TYPES = (TupleNode,)in_general.py, used by both classes, or - a parametrized test that runs each node-type rejection test from
test_audit.pyagainst every protocol that has its own reader.
The second one would also catch the same mistake in other nodes, so I'd lean towards it. Happy for that to be a follow-up.
There was a problem hiding this comment.
Agreed — happy to open a follow-up PR for the cross-protocol test!
|
|
||
|
|
||
| @pytest.mark.parametrize("protocol", [0, 1, 2]) | ||
| def test_operator_func_v2_wrong_child_type_is_rejected(protocol): |
There was a problem hiding this comment.
Could we widen this a little? At the moment it only covers itemgetter with a SliceNode in attrs. Two cases would be worth adding:
attrgetterandmethodcaller(parametrize over the operator function), so it doesn't matter which__class__reaches this reader;- an
attrsthat is an__id__memo reference to an earlier node that isn't a tuple, so the memo route is covered on the old path too, not only fresh nodes.
| protocol=protocol, | ||
| ) | ||
| msg = "Expected a node of type TupleNode, got SliceNode" | ||
| with pytest.raises(ValueError, match=msg): |
There was a problem hiding this comment.
Small one: the comment says the bad node is "refused before the audit", but the test only checks that loading fails. If get_tree ever moved the type check after node_cls(state, ...), the bad subtree would be built (and possibly memoized) before the error, and this test would still pass. If it's cheap, you could monkeypatch SliceNode.__init__ to fail, or count calls to it, and assert it's never reached. Otherwise just reword the comment to "is refused".
|
Thanks for the review @adrinjalali! Addressed the test suggestions in the latest commit:
Agreed that parametrizing the child-type rejection suite in |
Reference Issues/PRs
Follow-up to #547 and #551.
What does this implement/fix? Explain your changes.
#547 restricted
OperatorFuncNode.attrstoTupleNodeviaallowed_types=(TupleNode,)inskops.io._general, and #551 bumped the persistence protocol to 3 and moved the protocol<= 2reader toskops.io.old._general_v2.OperatorFuncNode.The protocol
<= 2reader still calledget_tree(state["attrs"], ...)withoutallowed_types, allowing a file declaringprotocol <= 2to bypass theTupleNodechild-kind check noted inskops.io._protocol. This PR passesallowed_types=(_general.TupleNode,)inskops/io/old/_general_v2.pyand adds a regression test intest_persist_old.pyacross protocols 0, 1, and 2.Any other comments?
No changelog entry added since both #547 and #551 are part of the unreleased
v0.17cycle and #547 already covers child-kind validation indocs/changes.rst.