Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black fails due to incompatible cache format #875

Closed
serhiy-storchaka opened this issue May 29, 2019 · 10 comments
Closed

Black fails due to incompatible cache format #875

serhiy-storchaka opened this issue May 29, 2019 · 10 comments
Labels
T: bug Something isn't working

Comments

@serhiy-storchaka
Copy link

Currently (19.3b0) Black uses the highest protocol for pickling the cache. In Python 3.8 it is 5. Protocol 5 is not supported on versions < 3.8. As a consequence, after using Black on 3.8 it becomes unusable on older Pythons.

Possible solutions:

  • Use the default protocol for pickling.
  • Include the protocol number or the Python version in the name of the cache file.
  • Ignore unpickling errors and continue as there is no cache.

These options can be applied together.

@zsol zsol added the T: bug Something isn't working label May 29, 2019
@cs01
Copy link

cs01 commented Aug 2, 2019

I just ran into this. The workaround for now is to remove the cache. Cache locations are described in black's readme and vary by os. See https://github.com/psf/black#ignoring-unmodified-files.

@zsol
Copy link
Collaborator

zsol commented Aug 2, 2019

This was also bugging the hell out of me while working on #943 and #711 so I might get around to fixing it soon

@vaneseltine
Copy link
Contributor

#1034 adds a test and fixes the issue.

I'd be tempted to make a bare except here, so that we simply return {} if there's any problem at all trying to read the cache. That would be a somewhat lazier but more future proof approach. Instead, I stuck with the current issue and added ValueError to the exceptions that read_cache will properly handle.

ambv pushed a commit that referenced this issue Oct 21, 2019
A black cache created in Python 3.8 throws an unhandled
ValueError in earlier versions. This is because 3.6 does
not recognize the pickle protocol used as default in 3.8.
Accordingly, this commit:

  - Fixes read_cache to return an empty cache instead.

  - Changes the pickle protocol to 4 as the highest protocol
    fully supported by black's supported Python versions.
@wimglenn
Copy link

wimglenn commented Oct 29, 2019

Exact error message to help google:

ValueError: unsupported pickle protocol: 5

Invalidating caches:

  • linux rm -rf ~/.cache/black
  • macOS rm -rf ~/Library/Caches/black
  • winblows rmdir /Q/S "%HOMEPATH%/AppData/Local/black"

@vaneseltine
Copy link
Contributor

Good tip.

Also possibly worth noting, in case of any odd problems, that the exact cache directory being used can be pulled from black's constants:

import black
print(black.CACHE_DIR)

@zsol
Copy link
Collaborator

zsol commented Oct 29, 2019

This shouldn't be necessary anymore

@TomFaulkner
Copy link

This shouldn't be necessary anymore

Ran into this today on a just installed black 19.3b0 on Python 3.8.0.

@vaneseltine
Copy link
Contributor

This shouldn't be necessary anymore

Ran into this today on a just installed black 19.3b0 on Python 3.8.0.

This is fixed in the latest stable release, 19.10b0. (19.3b0 was released in March.)

For many different reasons people can't or don't use the latest versions, so having the removal information seems handy to me. 😄

@TomFaulkner
Copy link

I had just pip installed it without pinning a version. Weird that I got an out of date version. I'll reinstall when I'm on that machine and see if I get the up-to-date version.

@cooperlees
Copy link
Collaborator

I believe this is all fixed.

HappyEinara added a commit to HappyEinara/cruft that referenced this issue Apr 14, 2021
On python3.9, version 18.9b0 currently pinned fails with
`AttributeError: type object '_asyncio.Task' has no attribute
'all_tasks'` on python3.9

Also ran into psf/black#875 while fixing this.
sambhav pushed a commit to cruft/cruft that referenced this issue Apr 14, 2021
* Update black to latest version.

On python3.9, version 18.9b0 currently pinned fails with
`AttributeError: type object '_asyncio.Task' has no attribute
'all_tasks'` on python3.9

Also ran into psf/black#875 while fixing this.

* Update `master` -> `main` for @timothycrosley's test repo.

* Cruft update to @timothycrosley's latest template.

* Update mypy to remove spurious errors.

* Update portray to fix Safety warning on mkdocs-material.

* Add python3.9 to Github Actions test matrix.
bgrant added a commit to salesforce/django-declarative-apis that referenced this issue May 28, 2021
There is a bug in 19.3b0 which may cause problems locally.  psf/black#875
bgrant added a commit to salesforce/django-declarative-apis that referenced this issue Jun 21, 2021
There is a bug in 19.3b0 which may cause problems locally.  psf/black#875
bgrant added a commit to salesforce/django-declarative-apis that referenced this issue Jun 29, 2021
* Update Black dev dependency

There is a bug in 19.3b0 which may cause problems locally.  psf/black#875

* Update CHANGELOG

* Update PR number in CHANGELOG

* Reformat after updating black.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants