question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: '_io.BufferedReader' object has no attribute 'temp'

See original GitHub issue

Hello,

I try to use LocalFileSystem with Transaction context manager and I get the following error:

AttributeError: '_io.BufferedReader' object has no attribute 'temp'

An example:

from fsspec.implementations.local import LocalFileSystem

def main():
    fs = LocalFileSystem()

    with fs.transaction:
        with fs.open('test.txt', 'w') as fp:
            fp.write('hello')

        with fs.open('test.txt', 'r') as fp:
            s = fp.read()
        
        print(s)

if __name__ == '__main__':
    main()

An exception:

Traceback (most recent call last):
  File "scratches\scratch_94.py", line 18, in <module>
    main()
  File "scratches\scratch_94.py", line 14, in main
    print(s)
  File "lib\site-packages\fsspec\transaction.py", line 24, in __exit__
    self.complete(commit=exc_type is None)
  File "lib\site-packages\fsspec\transaction.py", line 37, in complete
    f.commit()
  File "lib\site-packages\fsspec\implementations\local.py", line 246, in commit
    os.replace(self.temp, self.path)
  File "lib\site-packages\fsspec\implementations\local.py", line 261, in __getattr__
    return getattr(self.f, item)
AttributeError: '_io.BufferedReader' object has no attribute 'temp'

If I only use write operations within transaction context it works but read operation leads to the exception.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
andersy005commented, Feb 9, 2021

I’m opening a PR with your changes shortly

0reactions
andersy005commented, Feb 9, 2021

the original code should not work: the file “temp.txt” has not been finalised, so you should not be able to read it.

Aha! That’s it… Thank you for the clarification! I hadn’t payed attention to the location of the read context manager.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: '_io.BufferedReader' object has no attribute 'strip'
You are using str methods on an open file object. You can read the file as a list of lines by simply calling...
Read more >
'_io.BufferedReader' object has no attribute 'length ... - GitHub
Hi! I retrained two models myself (one for text detection, another one for text recognition). I'm trying to use the load_pretrained_params ...
Read more >
Fix '_io.BufferedReader' object has no attribute 'next'
An error occurred while retrieving approval data for this merge request. Fix '_io.BufferedReader' object has no attribute 'next'.
Read more >
Reading from Text Files - Springer Link
AttributeError : '_io.BufferedReader' object has no attribute 'encoding'. 1. Opening a file in binary mode is simple but subtle. The only difference from....
Read more >
'_io.BufferedReader' object has no...” : Bugs : Duplicity
AttributeError : '_io.BufferedReader' object has no attribute 'uc_name'. Bug #1852876 reported by Michael Terry on 2019-11-16.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found