Commit be782da
committed
Let memoize's ignore set match a positional arg by name
ignore={'session'} only worked when session was passed as a keyword.
Call the same function with session passed positionally instead and
diskcache tried to build a cache key that included the raw argument,
which is exactly the footgun described in #240: a caller has to know
whether they always call with keywords, or ignore has to spell out the
positional index too.
memoize() now grabs the wrapped function's parameter names once via
inspect.signature and passes them through to args_to_key, which checks
a positional argument's name against ignore in addition to its index.
Keyword matching was already fine and is untouched. args_to_key's new
arg_names parameter defaults to an empty tuple, so the two other
callers (DjangoCache.memoize, the memoize_stampede recipe) keep their
existing index-only behavior unless they're updated separately.
Added a regression test using an unpicklable value for the ignored
argument, so a caller passing it positionally raises immediately if it
leaks into the key instead of silently caching under a wrong key.1 parent ebfa37c commit be782da
2 files changed
Lines changed: 38 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
387 | | - | |
| 388 | + | |
388 | 389 | | |
389 | 390 | | |
390 | 391 | | |
391 | 392 | | |
392 | 393 | | |
393 | 394 | | |
394 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
395 | 399 | | |
396 | 400 | | |
397 | 401 | | |
398 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
399 | 408 | | |
400 | 409 | | |
401 | 410 | | |
| |||
1853 | 1862 | | |
1854 | 1863 | | |
1855 | 1864 | | |
1856 | | - | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
1857 | 1869 | | |
1858 | 1870 | | |
1859 | 1871 | | |
| |||
1865 | 1877 | | |
1866 | 1878 | | |
1867 | 1879 | | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
1868 | 1888 | | |
1869 | 1889 | | |
1870 | 1890 | | |
| |||
1880 | 1900 | | |
1881 | 1901 | | |
1882 | 1902 | | |
1883 | | - | |
| 1903 | + | |
1884 | 1904 | | |
1885 | 1905 | | |
1886 | 1906 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1393 | 1393 | | |
1394 | 1394 | | |
1395 | 1395 | | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
1396 | 1410 | | |
1397 | 1411 | | |
1398 | 1412 | | |
| |||
0 commit comments