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

Fix error when calling str() or repr() on GCS SeekableBufferedInputBase #442

Merged
merged 4 commits into from
Mar 25, 2020

Conversation

robcowie
Copy link
Contributor

Fix __repr__ and __str__ on gcs.SeekableBufferedInputBase by storing the bucket as _bucket instead of bucket.

This is now consistent with gcs.BufferedOutputBase and s3. _SeekableRawReader (which stores its S3 client as _object)

Motivation

We were seeing logging errors originating from smart_open:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1081, in emit msg = self.format(record)
  File "/usr/local/lib/python3.8/logging/__init__.py", line 925, in format return fmt.format(record)
  File "/usr/local/lib/python3.8/logging/__init__.py", line 664, in format record.message = record.getMessage()
  File "/usr/local/lib/python3.8/logging/__init__.py", line 369, in getMessage msg = msg % self.args
  File "/usr/local/lib/python3.8/gzip.py", line 220, in __repr__ s = repr(self.fileobj)
  File "/usr/local/lib/python3.8/site-packages/smart_open/gcs.py", line 379, in __repr__ self.__class__.__name__, self._bucket.name, self._blob.name, self._current_part_size, AttributeError: 'SeekableBufferedInputBase' object has no attribute '_bucket'

Store bucket object on SeekableBufferedInputBase._bucket as expected by
__repr__ and __str__.

Consistent with BufferedOutputBase.
smart_open/gcs.py Outdated Show resolved Hide resolved
To avoid storing unecessary complex objects.
@robcowie robcowie marked this pull request as ready for review March 23, 2020 19:29
smart_open/gcs.py Outdated Show resolved Hide resolved
@mpenkov mpenkov merged commit 7a33d9d into piskvorky:master Mar 25, 2020
@mpenkov
Copy link
Collaborator

mpenkov commented Mar 25, 2020

Merged. Thank you @robcowie for your contribution!

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.

None yet

3 participants