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

Breaking changes v6.0.0: attribute comparison #1236

Open
bram-tv opened this issue Apr 1, 2024 · 0 comments
Open

Breaking changes v6.0.0: attribute comparison #1236

bram-tv opened this issue Apr 1, 2024 · 0 comments

Comments

@bram-tv
Copy link

bram-tv commented Apr 1, 2024

The "breaking changes" list of v6.0.0 is missing a breaking change.

With PynamoDB v5.3.2 (and before) an equal check (==) on an attribute did an is check.
With PynamoDB v6.0.0 it returns a Comparison operator (which then fails in boolean context).

This change of behaviour was introduced in commit 163c75f for issue #508.

Sample code:

from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute

class UserModel(Model):
    """
    A DynamoDB User
    """
    class Meta:
        table_name = 'dynamodb-user'
        region = 'us-west-1'
    email = UnicodeAttribute(hash_key=True)
    first_name = UnicodeAttribute()
    last_name = UnicodeAttribute()


field = UserModel.email

if field == UserModel.email:
    print("Email field")
else:
    print("Not the email field")

Running with PynamoDB v5.3.2:

Email field

Running with PynamoDB v6.0.0

Traceback (most recent call last):
  File ".....py", line 18, in <module>
    if field == UserModel.email:
  File ".../site-packages/pynamodb/expressions/condition.py", line 58, in __bool__
    raise TypeError("unsupported operand type(s) for bool: {}".format(self.__class__.__name__))
TypeError: unsupported operand type(s) for bool: Comparison

The fix for the sample code:

if field == UserModel.email:

should be replaced with:

if field is UserModel.email:
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

No branches or pull requests

1 participant