Repository navigation
Commit 431778c
fix(extract): a decorator with arguments but no path is not a route
Distilled from DeusData#1245 by Andrew Hundt (a slice of d15071c), with a
different rule than upstream chose.
Python's unittest.mock is used as a decorator:
@patch("subprocess.run")
def test_runs(self, run): ...
decorator_method_name maps a bare `patch` to the HTTP method PATCH, and
try_route_from_decorator_call accepts a receiver-less decorator call.
When extract_route_path_from_args then finds nothing path-shaped, the
function falls back to "/". So every mock-decorated test function became
a Route handler, PATCH "/", and every one of those was wrong.
Upstream fixed it with a has_receiver heuristic. That still admits
@mock.patch("os.getcwd") (it has a receiver) and would reject the bare
framework decorators Litestar and BlackSheep use, @get("/x"). The rule
here is about the arguments, not the callee: a decorator call that HAS
arguments but none of them path-shaped is not a route. The "/" default
survives only for a zero-argument call such as @app.route(), which is the
one case where "/" is what the framework means. No test on main relied on
the default for a call with non-path arguments; checked before changing
it.
RED before the fix:
extract_python_mock_patch_is_not_route
FAIL tests/test_extraction.c:4023: mocked->route_path is not NULL
extract_python_bare_decorator_route_rules
FAIL tests/test_extraction.c:4063: mocked->route_path is not NULL
The second test also pins the two shapes that must keep working: bare
@get("/health") still yields a GET route, and zero-argument @app.route()
still yields "/" ANY -- those assertions passed before the fix and after.
GREEN after: extraction 351 passed; extraction pipeline edge_types_probe
route_canon cross_repo infrascan lang_contract 754 passed, with the
CALLS-breadth contract at 54 languages / 0 failures. The single remaining
red in both runs is extract_spill_round_trip_keeps_every_field refusing to
spill onto a disk below its 10 GB floor -- this host, not this change.
Co-authored-by: Andrew Hundt <ATHundt@gmail.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>1 parent 66d9c2b commit 431778c
2 files changed
Lines changed: 81 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1605 | 1605 | | |
1606 | 1606 | | |
1607 | 1607 | | |
1608 | | - | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
1609 | 1613 | | |
1610 | 1614 | | |
1611 | 1615 | | |
| |||
1630 | 1634 | | |
1631 | 1635 | | |
1632 | 1636 | | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
1633 | 1640 | | |
1634 | 1641 | | |
1635 | 1642 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4303 | 4303 | | |
4304 | 4304 | | |
4305 | 4305 | | |
| 4306 | + | |
| 4307 | + | |
| 4308 | + | |
| 4309 | + | |
| 4310 | + | |
| 4311 | + | |
| 4312 | + | |
| 4313 | + | |
| 4314 | + | |
| 4315 | + | |
| 4316 | + | |
| 4317 | + | |
| 4318 | + | |
| 4319 | + | |
| 4320 | + | |
| 4321 | + | |
| 4322 | + | |
| 4323 | + | |
| 4324 | + | |
| 4325 | + | |
| 4326 | + | |
| 4327 | + | |
| 4328 | + | |
| 4329 | + | |
| 4330 | + | |
| 4331 | + | |
| 4332 | + | |
| 4333 | + | |
| 4334 | + | |
| 4335 | + | |
| 4336 | + | |
| 4337 | + | |
| 4338 | + | |
| 4339 | + | |
| 4340 | + | |
| 4341 | + | |
| 4342 | + | |
| 4343 | + | |
| 4344 | + | |
| 4345 | + | |
| 4346 | + | |
| 4347 | + | |
| 4348 | + | |
| 4349 | + | |
| 4350 | + | |
| 4351 | + | |
| 4352 | + | |
| 4353 | + | |
| 4354 | + | |
| 4355 | + | |
| 4356 | + | |
| 4357 | + | |
| 4358 | + | |
| 4359 | + | |
| 4360 | + | |
| 4361 | + | |
| 4362 | + | |
| 4363 | + | |
| 4364 | + | |
| 4365 | + | |
| 4366 | + | |
| 4367 | + | |
| 4368 | + | |
| 4369 | + | |
| 4370 | + | |
| 4371 | + | |
| 4372 | + | |
| 4373 | + | |
| 4374 | + | |
| 4375 | + | |
| 4376 | + | |
4306 | 4377 | | |
4307 | 4378 | | |
4308 | 4379 | | |
| |||
8813 | 8884 | | |
8814 | 8885 | | |
8815 | 8886 | | |
| 8887 | + | |
| 8888 | + | |
8816 | 8889 | | |
8817 | 8890 | | |
8818 | 8891 | | |
| |||
0 commit comments