Raises a more explicit exception when a corrupted MemorizedResult is loaded#768
Conversation
Codecov Report
@@ Coverage Diff @@
## master #768 +/- ##
==========================================
- Coverage 95.41% 95.27% -0.15%
==========================================
Files 44 44
Lines 6262 6287 +25
==========================================
+ Hits 5975 5990 +15
- Misses 287 297 +10
Continue to review full report at Codecov.
|
|
Another option of course is not to change anything. |
|
Also please add as an inline comment that KeyError is expected under Python 2.7 and ValueError under Python 3. |
|
Ok, I did this. |
|
codecov is not 100% deterministic when reporting coverage on subprocess: they might be terminated before they have a chance to write their report. |
| ) | ||
| except KeyError as e: | ||
| message = "is corrupted" | ||
| assert message in str(e.args) |
There was a problem hiding this comment.
you could have used the pytest.raises context manager but this is fine.
|
Thanks, merged! |
* tag '0.13.0': Release 0.13.0 Use https (joblib#805) MTN bump loky to 2.4.2 (joblib#804) DOC: provide some useful variables for Makefile (joblib#794) DOC serialization and processes (joblib#803) ENH update loky 2.4.0 (joblib#802) FIX backward compatibility for nested backend (joblib#789) enable python 3.7 (joblib#795) memory: add test for call_and_shelve performance (joblib#791) FIX nested backend not changed by SequentialBackend (joblib#792) cloudpickle 0.6.0 (joblib#788) FIX nested backend setting n_jobs=-1 (joblib#785) Raises a more explicit exception when a corrupted MemorizedResult is loaded (joblib#768) Back to dev mode
* releases: Release 0.13.0 Use https (joblib#805) MTN bump loky to 2.4.2 (joblib#804) DOC: provide some useful variables for Makefile (joblib#794) DOC serialization and processes (joblib#803) ENH update loky 2.4.0 (joblib#802) FIX backward compatibility for nested backend (joblib#789) enable python 3.7 (joblib#795) memory: add test for call_and_shelve performance (joblib#791) FIX nested backend not changed by SequentialBackend (joblib#792) cloudpickle 0.6.0 (joblib#788) FIX nested backend setting n_jobs=-1 (joblib#785) Raises a more explicit exception when a corrupted MemorizedResult is loaded (joblib#768) Back to dev mode
When getting a reference with call_and_shelve, it's still possible that the underlying data gets corrupted (it raises an exception while trying to unpickle it).
This PR just wraps the .get method of MemorizedResult into a try/except, and adds an explicit message to the finally raised Exception.
I have found that pickle actually raises two kinds of Exceptions while unpickling. During my tests, it depended on the version of python that was used (KeyError for python 2.7 and ValueError for python 3).
Some existing tests were waiting for KeyError, so I used this one.
It would also be possible to use another one, like ValueError or a custom joblib exception, but it would require to change some tests, and could broke some users code..
I could also maybe just intercept the exception and add the explicit message, and reraise it again : in this way every user code that was expecting ValueError, or a KeyError could still catch it. It could still break code depending on what the user do with that exc.args (because we would have added an explicit message to it).