Skip to content

Raises a more explicit exception when a corrupted MemorizedResult is loaded#768

Merged
ogrisel merged 5 commits intojoblib:masterfrom
MaximeWeyl:memorized_result_corrupted
Oct 5, 2018
Merged

Raises a more explicit exception when a corrupted MemorizedResult is loaded#768
ogrisel merged 5 commits intojoblib:masterfrom
MaximeWeyl:memorized_result_corrupted

Conversation

@MaximeWeyl
Copy link
Copy Markdown
Contributor

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).

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 2, 2018

Codecov Report

Merging #768 into master will decrease coverage by 0.14%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
joblib/memory.py 95.61% <100%> (+0.06%) ⬆️
joblib/test/test_memory.py 98.05% <88.88%> (-0.14%) ⬇️
joblib/_parallel_backends.py 94.8% <0%> (-2.41%) ⬇️
joblib/test/test_format_stack.py 98.52% <0%> (-1.48%) ⬇️
joblib/test/test_memmapping.py 99.41% <0%> (-0.59%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e36e2d...6c063f6. Read the comment docs.

@MaximeWeyl
Copy link
Copy Markdown
Contributor Author

Another option of course is not to change anything.
The exception would be harder to understand, but it would still be one.

@ogrisel
Copy link
Copy Markdown
Contributor

ogrisel commented Sep 5, 2018

Also please add as an inline comment that KeyError is expected under Python 2.7 and ValueError under Python 3.

@MaximeWeyl
Copy link
Copy Markdown
Contributor Author

Ok, I did this.
I don't quite understand why is always codecov complaining about files I did not touch.

@ogrisel
Copy link
Copy Markdown
Contributor

ogrisel commented Oct 5, 2018

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could have used the pytest.raises context manager but this is fine.

@ogrisel ogrisel merged commit 9101ee9 into joblib:master Oct 5, 2018
@ogrisel
Copy link
Copy Markdown
Contributor

ogrisel commented Oct 5, 2018

Thanks, merged!

yarikoptic added a commit to yarikoptic/joblib that referenced this pull request Apr 12, 2019
* 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
yarikoptic added a commit to yarikoptic/joblib that referenced this pull request Apr 12, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants