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

DynamoDB's Binary type issues with Python 3 #846

Open
miguelgrinberg opened this issue Oct 12, 2016 · 7 comments
Open

DynamoDB's Binary type issues with Python 3 #846

miguelgrinberg opened this issue Oct 12, 2016 · 7 comments
Labels
dynamodb feature-request This issue requests a feature. p3 This is a minor priority issue

Comments

@miguelgrinberg
Copy link

The Binary class has a problematic implementation of the __str__() method that assumes str and bytes are interchangeable. Example:

Python 3.5.2 (default, Sep 28 2016, 18:11:34)
>>> from boto3.dynamodb.types import Binary
>>> b = Binary(b'hello')

>>> b
Binary(b'hello')

>>> print(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __str__ returned non-string (type bytes)

>>> bytes(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Binary' object is not iterable

The above examples all succeed under Python 2.7.

@kyleknap
Copy link
Member

Makes sense to have. We will take a look at your PR as well to make sure this gets implemented.

@kyleknap kyleknap added dynamodb feature-request This issue requests a feature. labels Oct 14, 2016
miguelgrinberg added a commit to miguelgrinberg/boto3 that referenced this issue Dec 3, 2016
@ghmj2417
Copy link

Bumping this issue as I just encountered it while using python3. Any idea if the fix presented by @miguelgrinberg is acceptable?

@scribu
Copy link

scribu commented Sep 20, 2018

Why is this marked as feature-request? It's a bug that happens in Python3.

Also, why is the Binary wrapper class needed at all?

@thetestgame
Copy link

This is currently preventing us from properly utilizing the Binary field in DynamoDB in our application. Is there an ETA on a potential fix for this issue?

@miguelgrinberg
Copy link
Author

FYI: I submitted a PR that addresses this issue (more than two years ago!!!): #848. So if your process allows it, you can install the PR branch to avoid the issue. Unfortunately the maintainers are slow or not interested in getting this fix out. :(

@mhball
Copy link

mhball commented Jun 21, 2019

I encountered this issue also. Found I could work around it by accessing the value directly. E.g.

Python 3.5.2 (default, Nov 12 2018, 13:43:14)
>>> from boto3.dynamodb.types import Binary
>>> b = Binary(b'hello')
>>> b
Binary(b'hello')

>>> print(b.value)
b'hello'

>>> print(b.value.decode("utf-8"))
hello

@aBurmeseDev
Copy link
Contributor

Just wanted to check in here and provide some updates.
This seems like Python 2 vs Python 3 issue and can potentially be fixed but we would need to do more investigation to find backwards-compatible solution. This is currently a low priority for us but please feel free to check in back here for updates.

For now, I would refer to the workaround provided by @mhball in previous comment. Thanks for sharing the workaround with others ❤️

@aBurmeseDev aBurmeseDev added p3 This is a minor priority issue and removed p2 This is a standard priority issue labels Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamodb feature-request This issue requests a feature. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

7 participants