fix: correctly detect flow-list/single-flow command results in the console - #8375
Open
citizen204 wants to merge 1 commit into
Open
fix: correctly detect flow-list/single-flow command results in the console#8375citizen204 wants to merge 1 commit into
citizen204 wants to merge 1 commit into
Conversation
…nsole CommandExecutor used `type(ret) == Sequence[flow.Flow]` and `type(ret) is flow.Flow` to decide whether a command's return value should be shown as a short status message. Neither check can ever be true at runtime: Python erases generic type parameters, so no concrete type is ever equal to the subscripted `Sequence[flow.Flow]`, and `type(x) is` only matches the exact base class, never a concrete subclass like HTTPFlow/TCPFlow/UDPFlow/DNSFlow. As a result, any command returning a list of flows (e.g. `view.flows.resolve @focus`) or a single flow always fell through to the DataViewerOverlay branch instead, which is at best the wrong UI and at worst crashes when the overlay's grid editor tries to deepcopy flows carrying connection state that isn't picklable. Fixes mitmproxy#4916 ## Changes - `mitmproxy/tools/console/commandexecutor.py`: replace the dead `type() ==`/`type() is` checks with `isinstance()`-based checks that actually match at runtime. - `test/mitmproxy/tools/console/test_commandexecutor.py`: add regression tests covering flow-list, single-flow, and non-flow command results.
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
CommandExecutordecides whether a command's return value should be shown as ashort status message using
type(ret) == Sequence[flow.Flow]andtype(ret) is flow.Flow. Neither check can ever be true at runtime: Pythonerases generic parameters, so no concrete type ever equals the subscripted
Sequence[flow.Flow], andtype(x) is flow.Flowonly matches the exact baseclass, never a concrete subclass like
HTTPFlow/TCPFlow/UDPFlow/DNSFlow— which is what every real command actually returns.
As a result, any command returning a list of flows (e.g.
view.flows.resolve @focus) or a single flow always fell through to theDataViewerOverlaybranch instead of the intended status message. Thatoverlay's grid editor deepcopies its input, which is how the original report
crashed with
TypeError: cannot pickle 'Context' object. I could no longerreproduce the exact pickling crash with current flow/connection objects (it
may have been incidentally fixed by unrelated refactors), but the dead
type-check itself is still very much present and still routes flow-list
results to the wrong UI — confirmed with a regression test that fails against
current
main(the overlay mock is called when it shouldn't be) and passesafter this fix.
Fixes #4916
Changes
mitmproxy/tools/console/commandexecutor.py: replace the deadtype() ==/type() ischecks withisinstance()-based checks that actually match atruntime, plus an explicit non-empty/non-str guard for the sequence case.
test/mitmproxy/tools/console/test_commandexecutor.py: new regressiontests covering flow-list, single-flow, and non-flow command results
(verified fail-before / pass-after via
git stash).🤖 Generated with Claude Code